|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# rad2degf |
| 22 | + |
| 23 | +> Convert an angle from radians to degrees (single-precision). |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var rad2degf = require( '@stdlib/math/base/special/rad2degf' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### rad2degf( x ) |
| 34 | + |
| 35 | +Converts an angle from radians to degrees (single-precision). |
| 36 | + |
| 37 | +```javascript |
| 38 | +var d = rad2degf( 3.141592653589793 / 2.0 ); |
| 39 | +// returns 90.0 |
| 40 | + |
| 41 | +d = rad2degf( -3.141592653589793 / 4.0 ); |
| 42 | +// returns -45.0 |
| 43 | + |
| 44 | +d = rad2degf( NaN ); |
| 45 | +// returns NaN |
| 46 | +``` |
| 47 | + |
| 48 | +</section> |
| 49 | + |
| 50 | +<!-- /.usage --> |
| 51 | + |
| 52 | +<section class="notes"> |
| 53 | + |
| 54 | +## Notes |
| 55 | + |
| 56 | +- Due to finite precision, canonical values may not be returned. For example, |
| 57 | + |
| 58 | + ```javascript |
| 59 | + var d = rad2degf( 3.141592653589793 / 6.0 ); |
| 60 | + // returns 30.000001907348633 |
| 61 | + ``` |
| 62 | + |
| 63 | +</section> |
| 64 | + |
| 65 | +<!-- /.notes --> |
| 66 | + |
| 67 | +<section class="examples"> |
| 68 | + |
| 69 | +## Examples |
| 70 | + |
| 71 | +<!-- eslint no-undef: "error" --> |
| 72 | + |
| 73 | +```javascript |
| 74 | +var randu = require( '@stdlib/random/base/randu' ); |
| 75 | +var TWO_PI = require( '@stdlib/constants/float32/two-pi' ); |
| 76 | +var rad2degf = require( '@stdlib/math/base/special/rad2degf' ); |
| 77 | +
|
| 78 | +var r; |
| 79 | +var d; |
| 80 | +var i; |
| 81 | +
|
| 82 | +for ( i = 0; i < 100; i++ ) { |
| 83 | + r = randu() * TWO_PI; |
| 84 | + d = rad2degf( r ); |
| 85 | + console.log( 'radians: %d => degrees: %d', r, d ); |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +</section> |
| 90 | + |
| 91 | +<!-- /.examples --> |
| 92 | + |
| 93 | +<!-- C interface documentation. --> |
| 94 | + |
| 95 | +* * * |
| 96 | + |
| 97 | +<section class="c"> |
| 98 | + |
| 99 | +## C APIs |
| 100 | + |
| 101 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 102 | + |
| 103 | +<section class="intro"> |
| 104 | + |
| 105 | +</section> |
| 106 | + |
| 107 | +<!-- /.intro --> |
| 108 | + |
| 109 | +<!-- C usage documentation. --> |
| 110 | + |
| 111 | +<section class="usage"> |
| 112 | + |
| 113 | +### Usage |
| 114 | + |
| 115 | +```c |
| 116 | +#include "stdlib/math/base/special/rad2degf.h" |
| 117 | +``` |
| 118 | + |
| 119 | +#### stdlib_base_rad2degf( x ) |
| 120 | + |
| 121 | +Converts an angle from radians to degrees (single-precision). |
| 122 | + |
| 123 | +```c |
| 124 | +float x = 3.141592653589793f / 2.0f; |
| 125 | +float d = stdlib_base_rad2degf( x ); |
| 126 | +// returns 90.0f |
| 127 | +
|
| 128 | +x = -3.141592653589793f / 4.0f; |
| 129 | +d = stdlib_base_rad2degf( x ); |
| 130 | +// returns -45.0f |
| 131 | +``` |
| 132 | + |
| 133 | +The function accepts the following arguments: |
| 134 | + |
| 135 | +- **x**: `[in] float` input value (in radians). |
| 136 | + |
| 137 | +```c |
| 138 | +float stdlib_base_rad2degf( const float x ); |
| 139 | +``` |
| 140 | + |
| 141 | +</section> |
| 142 | + |
| 143 | +<!-- /.usage --> |
| 144 | + |
| 145 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 146 | + |
| 147 | +<section class="notes"> |
| 148 | + |
| 149 | +</section> |
| 150 | + |
| 151 | +<!-- /.notes --> |
| 152 | + |
| 153 | +<!-- C API usage examples. --> |
| 154 | + |
| 155 | +<section class="examples"> |
| 156 | + |
| 157 | +### Examples |
| 158 | + |
| 159 | +```c |
| 160 | +#include "stdlib/math/base/special/rad2degf.h" |
| 161 | +#include "stdlib/constants/float32/two_pi.h" |
| 162 | +#include <stdlib.h> |
| 163 | +#include <stdio.h> |
| 164 | + |
| 165 | +int main( void ) { |
| 166 | + float x; |
| 167 | + float d; |
| 168 | + int i; |
| 169 | + |
| 170 | + for ( i = 0; i < 100; i++ ) { |
| 171 | + x = (float)rand() / (float)RAND_MAX * STDLIB_CONSTANT_FLOAT32_TWO_PI; |
| 172 | + d = stdlib_base_rad2degf( x ); |
| 173 | + printf( "radians: %f => degrees: %f\n", x, d ); |
| 174 | + } |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +</section> |
| 179 | + |
| 180 | +<!-- /.examples --> |
| 181 | + |
| 182 | +</section> |
| 183 | + |
| 184 | +<!-- /.c --> |
| 185 | + |
| 186 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 187 | + |
| 188 | +<section class="related"> |
| 189 | + |
| 190 | +</section> |
| 191 | + |
| 192 | +<!-- /.related --> |
| 193 | + |
| 194 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 195 | + |
| 196 | +<section class="links"> |
| 197 | + |
| 198 | +</section> |
| 199 | + |
| 200 | +<!-- /.links --> |
0 commit comments