|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2018 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 | +# Versine |
| 22 | + |
| 23 | +> Compute the [versed sine][versed-sine]. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [versed sine][versed-sine] is defined as |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:versine" align="center" raw="\operatorname{versin}(\theta) = 1 - \cos \theta" alt="Versed sine."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathop{\mathrm{versin}}(\theta) = 1 - \cos \theta |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <div class="equation" align="center" data-raw-text="\operatorname{versin}(\theta) = 1 - \cos \theta" data-equation="eq:versine"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/versin/docs/img/equation_versine.svg" alt="Versed sine."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +</section> |
| 43 | + |
| 44 | +<!-- /.intro --> |
| 45 | + |
| 46 | +<section class="usage"> |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +```javascript |
| 51 | +var versin = require( '@stdlib/math/base/special/versin' ); |
| 52 | +``` |
| 53 | + |
| 54 | +#### versin( x ) |
| 55 | + |
| 56 | +Computes the [versed sine][versed-sine] of a `number` (in radians). |
| 57 | + |
| 58 | +```javascript |
| 59 | +var v = versin( 0.0 ); |
| 60 | +// returns 0.0 |
| 61 | + |
| 62 | +v = versin( 3.141592653589793/2.0 ); |
| 63 | +// returns ~1.0 |
| 64 | + |
| 65 | +v = versin( -3.141592653589793/6.0 ); |
| 66 | +// returns ~0.13397 |
| 67 | +``` |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.usage --> |
| 72 | + |
| 73 | +<section class="examples"> |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +<!-- eslint no-undef: "error" --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 81 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 82 | +var TWO_PI = require( '@stdlib/constants/float64/two-pi' ); |
| 83 | +var versin = require( '@stdlib/math/base/special/versin' ); |
| 84 | + |
| 85 | +var opts = { |
| 86 | + 'dtype': 'float64' |
| 87 | +}; |
| 88 | +var x = uniform( 100, 0.0, TWO_PI, opts ); |
| 89 | + |
| 90 | +logEachMap( 'versin(%0.4f) = %0.4f', x, versin ); |
| 91 | +``` |
| 92 | + |
| 93 | +</section> |
| 94 | + |
| 95 | +<!-- /.examples --> |
| 96 | + |
| 97 | +<!-- C interface documentation. --> |
| 98 | + |
| 99 | +* * * |
| 100 | + |
| 101 | +<section class="c"> |
| 102 | + |
| 103 | +## C APIs |
| 104 | + |
| 105 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 106 | + |
| 107 | +<section class="intro"> |
| 108 | + |
| 109 | +</section> |
| 110 | + |
| 111 | +<!-- /.intro --> |
| 112 | + |
| 113 | +<!-- C usage documentation. --> |
| 114 | + |
| 115 | +<section class="usage"> |
| 116 | + |
| 117 | +### Usage |
| 118 | + |
| 119 | +```c |
| 120 | +#include "stdlib/math/base/special/versin.h" |
| 121 | +``` |
| 122 | + |
| 123 | +#### stdlib_base_versin( x ) |
| 124 | + |
| 125 | +Computes the [versed sine][versed-sine] of a `number` (in radians). |
| 126 | + |
| 127 | +```c |
| 128 | +double out = stdlib_base_versin( 0.0 ); |
| 129 | +// returns 0.0 |
| 130 | + |
| 131 | +out = stdlib_base_versin( 3.141592653589793 / 2.0 ); |
| 132 | +// returns ~1.0 |
| 133 | +``` |
| 134 | + |
| 135 | +The function accepts the following arguments: |
| 136 | + |
| 137 | +- **x**: `[in] double` input value. |
| 138 | + |
| 139 | +```c |
| 140 | +double stdlib_base_versin( const double x ); |
| 141 | +``` |
| 142 | +
|
| 143 | +</section> |
| 144 | +
|
| 145 | +<!-- /.usage --> |
| 146 | +
|
| 147 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 148 | +
|
| 149 | +<section class="notes"> |
| 150 | +
|
| 151 | +</section> |
| 152 | +
|
| 153 | +<!-- /.notes --> |
| 154 | +
|
| 155 | +<!-- C API usage examples. --> |
| 156 | +
|
| 157 | +<section class="examples"> |
| 158 | +
|
| 159 | +### Examples |
| 160 | +
|
| 161 | +```c |
| 162 | +#include "stdlib/math/base/special/versin.h" |
| 163 | +#include <stdio.h> |
| 164 | +
|
| 165 | +int main( void ) { |
| 166 | + const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 }; |
| 167 | +
|
| 168 | + double y; |
| 169 | + int i; |
| 170 | + for ( i = 0; i < 5; i++ ) { |
| 171 | + y = stdlib_base_versin( x[ i ] ); |
| 172 | + printf( "versin(%lf) = %lf\n", x[ i ], y ); |
| 173 | + } |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.examples --> |
| 180 | + |
| 181 | +</section> |
| 182 | + |
| 183 | +<!-- /.c --> |
| 184 | + |
| 185 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 186 | + |
| 187 | +<section class="related"> |
| 188 | + |
| 189 | +* * * |
| 190 | + |
| 191 | +## See Also |
| 192 | + |
| 193 | +- <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> |
| 194 | +- <span class="package-name">[`@stdlib/math/base/special/sin`][@stdlib/math/base/special/sin]</span><span class="delimiter">: </span><span class="description">compute the sine of a number.</span> |
| 195 | +- <span class="package-name">[`@stdlib/math/base/special/vercos`][@stdlib/math/base/special/vercos]</span><span class="delimiter">: </span><span class="description">compute the versed cosine.</span> |
| 196 | + |
| 197 | +</section> |
| 198 | + |
| 199 | +<!-- /.related --> |
| 200 | + |
| 201 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 202 | + |
| 203 | +<section class="links"> |
| 204 | + |
| 205 | +[versed-sine]: https://en.wikipedia.org/wiki/Versine |
| 206 | + |
| 207 | +<!-- <related-links> --> |
| 208 | + |
| 209 | +[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos |
| 210 | + |
| 211 | +[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin |
| 212 | + |
| 213 | +[@stdlib/math/base/special/vercos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/vercos |
| 214 | + |
| 215 | +<!-- </related-links> --> |
| 216 | + |
| 217 | +</section> |
| 218 | + |
| 219 | +<!-- /.links --> |
0 commit comments