|
| 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 | +# gcdf |
| 22 | + |
| 23 | +> Compute the [greatest common divisor][gcd] (gcd) of two single-precision floating point numbers. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +The [greatest common divisor][gcd] (gcd) of two non-zero integers `a` and `b` is the largest positive integer which divides both `a` and `b` without a remainder. The gcd is also known as the **greatest common factor** (gcf), **highest common factor** (hcf), **highest common divisor**, and **greatest common measure** (gcm). |
| 30 | + |
| 31 | +</section> |
| 32 | + |
| 33 | +<!-- /.intro --> |
| 34 | + |
| 35 | +<!-- Package usage documentation. --> |
| 36 | + |
| 37 | +<section class="usage"> |
| 38 | + |
| 39 | +## Usage |
| 40 | + |
| 41 | +```javascript |
| 42 | +var gcdf = require( '@stdlib/math/base/special/gcdf' ); |
| 43 | +``` |
| 44 | + |
| 45 | +#### gcdf( a, b ) |
| 46 | + |
| 47 | +Computes the [greatest common divisor][gcd] (gcd). |
| 48 | + |
| 49 | +```javascript |
| 50 | +var v = gcdf( 48, 18 ); |
| 51 | +// returns 6 |
| 52 | +``` |
| 53 | + |
| 54 | +If both `a` and `b` are `0`, the function returns `0`. |
| 55 | + |
| 56 | +```javascript |
| 57 | +var v = gcdf( 0, 0 ); |
| 58 | +// returns 0 |
| 59 | +``` |
| 60 | + |
| 61 | +Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. |
| 62 | + |
| 63 | +```javascript |
| 64 | +var v = gcdf( 3.14, 18 ); |
| 65 | +// returns NaN |
| 66 | + |
| 67 | +v = gcdf( 48, 3.14 ); |
| 68 | +// returns NaN |
| 69 | + |
| 70 | +v = gcdf( NaN, 18 ); |
| 71 | +// returns NaN |
| 72 | + |
| 73 | +v = gcdf( 48, NaN ); |
| 74 | +// returns NaN |
| 75 | +``` |
| 76 | + |
| 77 | +</section> |
| 78 | + |
| 79 | +<!-- /.usage --> |
| 80 | + |
| 81 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 82 | + |
| 83 | +<section class="notes"> |
| 84 | + |
| 85 | +</section> |
| 86 | + |
| 87 | +<!-- /.notes --> |
| 88 | + |
| 89 | +<!-- Package usage examples. --> |
| 90 | + |
| 91 | +<section class="examples"> |
| 92 | + |
| 93 | +## Examples |
| 94 | + |
| 95 | +<!-- eslint no-undef: "error" --> |
| 96 | + |
| 97 | +```javascript |
| 98 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 99 | +var gcdf = require( '@stdlib/math/base/special/gcdf' ); |
| 100 | + |
| 101 | +var a = discreteUniform( 100, 0, 50 ); |
| 102 | +var b = discreteUniform( a.length, 0, 50 ); |
| 103 | + |
| 104 | +var i; |
| 105 | +for ( i = 0; i < a.length; i++ ) { |
| 106 | + console.log( 'gcdf(%d,%d) = %d', a[ i ], b[ i ], gcdf( a[ i ], b[ i ] ) ); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.examples --> |
| 113 | + |
| 114 | +<!-- C interface documentation. --> |
| 115 | + |
| 116 | +* * * |
| 117 | + |
| 118 | +<section class="c"> |
| 119 | + |
| 120 | +## C APIs |
| 121 | + |
| 122 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 123 | + |
| 124 | +<section class="intro"> |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.intro --> |
| 129 | + |
| 130 | +<!-- C usage documentation. --> |
| 131 | + |
| 132 | +<section class="usage"> |
| 133 | + |
| 134 | +### Usage |
| 135 | + |
| 136 | +```c |
| 137 | +#include "stdlib/math/base/special/gcdf.h" |
| 138 | +``` |
| 139 | + |
| 140 | +#### stdlib_base_gcdf( a, b ) |
| 141 | + |
| 142 | +Computes the greatest common divisor (gcd). |
| 143 | + |
| 144 | +```c |
| 145 | +float v = stdlib_base_gcdf( 48.0f, 18.0f ); |
| 146 | +// returns 6.0f |
| 147 | +``` |
| 148 | + |
| 149 | +The function accepts the following arguments: |
| 150 | + |
| 151 | +- **a**: `[in] float` input value. |
| 152 | +- **b**: `[in] float` input value. |
| 153 | + |
| 154 | +```c |
| 155 | +float stdlib_base_gcdf( const float a, const float b ); |
| 156 | +``` |
| 157 | +
|
| 158 | +</section> |
| 159 | +
|
| 160 | +<!-- /.usage --> |
| 161 | +
|
| 162 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 163 | +
|
| 164 | +<section class="notes"> |
| 165 | +
|
| 166 | +</section> |
| 167 | +
|
| 168 | +<!-- /.notes --> |
| 169 | +
|
| 170 | +<!-- C API usage examples. --> |
| 171 | +
|
| 172 | +<section class="examples"> |
| 173 | +
|
| 174 | +### Examples |
| 175 | +
|
| 176 | +```c |
| 177 | +#include "stdlib/math/base/special/gcdf.h" |
| 178 | +#include <stdio.h> |
| 179 | +
|
| 180 | +int main( void ) { |
| 181 | + const float a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; |
| 182 | + const float b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; |
| 183 | +
|
| 184 | + float out; |
| 185 | + int i; |
| 186 | + for ( i = 0; i < 5; i++ ) { |
| 187 | + out = stdlib_base_gcdf( a[ i ], b[ i ] ); |
| 188 | + printf( "gcdf(%f, %f) = %f\n", a[ i ], b[ i ], out ); |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +</section> |
| 194 | + |
| 195 | +<!-- /.examples --> |
| 196 | + |
| 197 | +</section> |
| 198 | + |
| 199 | +<!-- /.c --> |
| 200 | + |
| 201 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 202 | + |
| 203 | +<section class="references"> |
| 204 | + |
| 205 | +## References |
| 206 | + |
| 207 | +- Stein, Josef. 1967. "Computational problems associated with Racah algebra." _Journal of Computational Physics_ 1 (3): 397–405. doi:[10.1016/0021-9991(67)90047-2][@stein:1967]. |
| 208 | + |
| 209 | +</section> |
| 210 | + |
| 211 | +<!-- /.references --> |
| 212 | + |
| 213 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 214 | + |
| 215 | +<section class="related"> |
| 216 | + |
| 217 | +</section> |
| 218 | + |
| 219 | +<!-- /.related --> |
| 220 | + |
| 221 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 222 | + |
| 223 | +<section class="links"> |
| 224 | + |
| 225 | +[gcd]: https://en.wikipedia.org/wiki/Greatest_common_divisor |
| 226 | + |
| 227 | +[@stein:1967]: https://doi.org/10.1016/0021-9991(67)90047-2 |
| 228 | + |
| 229 | +<!-- <related-links> --> |
| 230 | + |
| 231 | +<!-- </related-links> --> |
| 232 | + |
| 233 | +</section> |
| 234 | + |
| 235 | +<!-- /.links --> |
0 commit comments