|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# cosm1f |
| 22 | + |
| 23 | +> Compute `cos(x) - 1`. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var cosm1f = require( '@stdlib/math/base/special/cosm1f' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### cosm1f( x ) |
| 34 | + |
| 35 | +Computes `cos(x) - 1`, where `cos` is the [cosine][@stdlib/math/base/special/cos] of a `number` (in radians). This function should be used instead of manually calculating `cos(x) - 1` when the argument is near unity. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var PI = require( '@stdlib/constants/float64/pi' ); |
| 39 | + |
| 40 | +var v = cosm1f( 0.0 ); |
| 41 | +// returns 0.0 |
| 42 | + |
| 43 | +v = cosm1f( PI/4.0 ); |
| 44 | +// returns ~-0.293 |
| 45 | + |
| 46 | +v = cosm1f( -PI/6.0 ); |
| 47 | +// returns ~-0.134 |
| 48 | + |
| 49 | +v = cosm1f( NaN ); |
| 50 | +// returns NaN |
| 51 | +``` |
| 52 | + |
| 53 | +</section> |
| 54 | + |
| 55 | +<!-- /.usage --> |
| 56 | + |
| 57 | +<section class="examples"> |
| 58 | + |
| 59 | +## Examples |
| 60 | + |
| 61 | +<!-- eslint no-undef: "error" --> |
| 62 | + |
| 63 | +```javascript |
| 64 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 65 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 66 | +var PI = require( '@stdlib/constants/float64/pi' ); |
| 67 | +var cosm1f = require( '@stdlib/math/base/special/cosm1f' ); |
| 68 | + |
| 69 | +var opts = { |
| 70 | + 'dtype': 'float64' |
| 71 | +}; |
| 72 | +var x = uniform( 100, 0.0, 2.0*PI, opts ); |
| 73 | + |
| 74 | +logEachMap( 'cos(%0.4f) - 1 = %0.4f', x, cosm1f ); |
| 75 | +``` |
| 76 | + |
| 77 | +</section> |
| 78 | + |
| 79 | +<!-- /.examples --> |
| 80 | + |
| 81 | +<!-- C interface documentation. --> |
| 82 | + |
| 83 | +* * * |
| 84 | + |
| 85 | +<section class="c"> |
| 86 | + |
| 87 | +## C APIs |
| 88 | + |
| 89 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 90 | + |
| 91 | +<section class="intro"> |
| 92 | + |
| 93 | +</section> |
| 94 | + |
| 95 | +<!-- /.intro --> |
| 96 | + |
| 97 | +<!-- C usage documentation. --> |
| 98 | + |
| 99 | +<section class="usage"> |
| 100 | + |
| 101 | +### Usage |
| 102 | + |
| 103 | +```c |
| 104 | +#include "stdlib/math/base/special/cosm1f.h" |
| 105 | +``` |
| 106 | + |
| 107 | +#### stdlib_base_cosm1( x ) |
| 108 | + |
| 109 | +Computes `cos(x) - 1`, where `cos` is the [cosine][@stdlib/math/base/special/cos] of a `number` (in radians). This function should be used instead of manually calculating `cos(x) - 1` when the argument is near unity. |
| 110 | + |
| 111 | +```c |
| 112 | +double out = stdlib_base_cosm1( 0.0 ); |
| 113 | +// returns 0.0 |
| 114 | + |
| 115 | +out = stdlib_base_cosm1( 3.141592653589793238 / 4.0 ); |
| 116 | +// returns ~-0.293 |
| 117 | +``` |
| 118 | + |
| 119 | +The function accepts the following arguments: |
| 120 | + |
| 121 | +- **x**: `[in] double` input value. |
| 122 | + |
| 123 | +```c |
| 124 | +double stdlib_base_cosm1( const double x ); |
| 125 | +``` |
| 126 | +
|
| 127 | +</section> |
| 128 | +
|
| 129 | +<!-- /.usage --> |
| 130 | +
|
| 131 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 132 | +
|
| 133 | +<section class="notes"> |
| 134 | +
|
| 135 | +</section> |
| 136 | +
|
| 137 | +<!-- /.notes --> |
| 138 | +
|
| 139 | +<!-- C API usage examples. --> |
| 140 | +
|
| 141 | +<section class="examples"> |
| 142 | +
|
| 143 | +### Examples |
| 144 | +
|
| 145 | +```c |
| 146 | +#include "stdlib/math/base/special/cosm1f.h" |
| 147 | +#include <stdio.h> |
| 148 | +
|
| 149 | +int main( void ) { |
| 150 | + const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 }; |
| 151 | +
|
| 152 | + double y; |
| 153 | + int i; |
| 154 | + for ( i = 0; i < 5; i++ ) { |
| 155 | + y = stdlib_base_cosm1( x[ i ] ); |
| 156 | + printf( "cosm1f(%lf) = %lf\n", x[ i ], y ); |
| 157 | + } |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +</section> |
| 162 | + |
| 163 | +<!-- /.examples --> |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.c --> |
| 168 | + |
| 169 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 170 | + |
| 171 | +<section class="related"> |
| 172 | + |
| 173 | +* * * |
| 174 | + |
| 175 | +## See Also |
| 176 | + |
| 177 | +- <span class="package-name">[`@stdlib/math/base/special/cos`][@stdlib/math/base/special/cos]</span><span class="delimiter">: </span><span class="description">compute the cosine of a number.</span> |
| 178 | + |
| 179 | +</section> |
| 180 | + |
| 181 | +<!-- /.related --> |
| 182 | + |
| 183 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 184 | + |
| 185 | +<section class="links"> |
| 186 | + |
| 187 | +<!-- <related-links> --> |
| 188 | + |
| 189 | +[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos |
| 190 | + |
| 191 | +<!-- </related-links> --> |
| 192 | + |
| 193 | +</section> |
| 194 | + |
| 195 | +<!-- /.links --> |
0 commit comments