|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +
|
| 17 | +--> |
| 18 | + |
| 19 | +# lcmf |
| 20 | + |
| 21 | +> Compute the [least common multiple][lcm] of all integers from 1 up to a specified integer \( n \). |
| 22 | +
|
| 23 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 24 | + |
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [least common multiple][lcm] of a set of integers is the smallest positive integer that is divisible by each number in the set. This function computes the LCM[lcm] for all integers from 1 up to a given integer \( n \), which is especially useful in various mathematical and computational applications. |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var lcmf = require( '@stdlib/math/base/special/lcmf' ); |
| 41 | +``` |
| 42 | + |
| 43 | +### lcmf(n) |
| 44 | +Computes the [least common multiple][lcm] for all integers from 1 up to n. |
| 45 | + |
| 46 | +```javascript |
| 47 | +var v = lcmf( 10 ); |
| 48 | +// returns 2520 |
| 49 | +``` |
| 50 | + |
| 51 | +If n is less than 1, the function returns 0. |
| 52 | + |
| 53 | +```javascript |
| 54 | +var v = lcmf( 0 ); |
| 55 | +// returns 0 |
| 56 | + |
| 57 | +v = lcmf( -5 ); |
| 58 | +// returns 0 |
| 59 | +``` |
| 60 | + |
| 61 | +The input n must be an integer; otherwise, the function returns NaN. |
| 62 | + |
| 63 | +```javascript |
| 64 | +var v = lcmf( 3.14 ); |
| 65 | +// returns NaN |
| 66 | + |
| 67 | +v = lcmf( NaN ); |
| 68 | +// returns NaN |
| 69 | +``` |
| 70 | + |
| 71 | +</section> |
| 72 | + |
| 73 | +<!-- /.usage --> |
| 74 | + |
| 75 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 76 | + |
| 77 | +<section class="notes"> |
| 78 | + |
| 79 | +</section> |
| 80 | + |
| 81 | +<!-- /.notes --> |
| 82 | + |
| 83 | +<!-- Package usage examples. --> |
| 84 | + |
| 85 | +<section class="examples"> |
| 86 | + |
| 87 | +## Examples |
| 88 | + |
| 89 | +<!-- eslint no-undef: "error" --> |
| 90 | + |
| 91 | +```javascript |
| 92 | +var lcmf = require( '@stdlib/math/base/special/lcmf' ); |
| 93 | + |
| 94 | +var v; |
| 95 | +var i; |
| 96 | + |
| 97 | +for ( i = 1; i <= 10; i++ ) { |
| 98 | + v = lcmf( i ); |
| 99 | + console.log( 'lcm(1 to %d) = %d', i, v ); |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +</section> |
| 104 | + |
| 105 | +<!-- /.examples --> |
| 106 | + |
| 107 | +<!-- C interface documentation. --> |
| 108 | + |
| 109 | +* * * |
| 110 | + |
| 111 | +<section class="c"> |
| 112 | + |
| 113 | +## C APIs |
| 114 | + |
| 115 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 116 | + |
| 117 | +<section class="intro"> |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.intro --> |
| 122 | + |
| 123 | +<!-- C usage documentation. --> |
| 124 | + |
| 125 | +<section class="usage"> |
| 126 | + |
| 127 | +### Usage |
| 128 | + |
| 129 | +```c |
| 130 | +#include "stdlib/math/base/special/lcmf.h" |
| 131 | +``` |
| 132 | + |
| 133 | +### stdlib_base_lcmf( n ) |
| 134 | + |
| 135 | +Computes the [least common multiple][lcm] for all integers from 1 up to n. |
| 136 | + |
| 137 | +```c |
| 138 | +double v = stdlib_base_lcmf( 10 ); |
| 139 | +// returns 2520.0 |
| 140 | +``` |
| 141 | + |
| 142 | +The function accepts the following argument: |
| 143 | + |
| 144 | +- **n**: `[in] double` input value. |
| 145 | + |
| 146 | +```c |
| 147 | +double stdlib_base_lcmf( const double n ); |
| 148 | +``` |
| 149 | +
|
| 150 | +</section> |
| 151 | +
|
| 152 | +<!-- /.usage --> |
| 153 | +
|
| 154 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 155 | +
|
| 156 | +<section class="notes"> |
| 157 | +
|
| 158 | +</section> |
| 159 | +
|
| 160 | +<!-- /.notes --> |
| 161 | +
|
| 162 | +<!-- C API usage examples. --> |
| 163 | +
|
| 164 | +<section class="examples"> |
| 165 | +
|
| 166 | +### Examples |
| 167 | +
|
| 168 | +```c |
| 169 | +#include "stdlib/math/base/special/lcmf.h" |
| 170 | +#include <stdio.h> |
| 171 | +
|
| 172 | +int main( void ) { |
| 173 | + double v; |
| 174 | + int i; |
| 175 | + for ( i = 1; i <= 10; i++ ) { |
| 176 | + v = stdlib_base_lcmf( i ); |
| 177 | + printf( "lcm(1 to %d) = %lf\n", i, v ); |
| 178 | + } |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | +</section> |
| 183 | + |
| 184 | +<!-- /.examples --> |
| 185 | + |
| 186 | +</section> |
| 187 | + |
| 188 | +<!-- /.c --> |
| 189 | + |
| 190 | +<!-- 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. --> |
| 191 | + |
| 192 | +<section class="references"> |
| 193 | + |
| 194 | +</section> |
| 195 | + |
| 196 | +<!-- /.references --> |
| 197 | + |
| 198 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 199 | + |
| 200 | +<section class="related"> |
| 201 | + |
| 202 | +* * * |
| 203 | + |
| 204 | +## See Also |
| 205 | + |
| 206 | +- <span class="package-name">[`@stdlib/math/base/special/gcd`][@stdlib/math/base/special/gcd]</span><span class="delimiter">: </span><span class="description">compute the greatest common divisor (gcd).</span> |
| 207 | + |
| 208 | +</section> |
| 209 | + |
| 210 | +<!-- /.related --> |
| 211 | + |
| 212 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 213 | + |
| 214 | +<section class="links"> |
| 215 | + |
| 216 | +[lcm]: https://en.wikipedia.org/wiki/Least_common_multiple |
| 217 | + |
| 218 | +<!-- <related-links> --> |
| 219 | + |
| 220 | +[@stdlib/math/base/special/gcd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gcd |
| 221 | + |
| 222 | +<!-- </related-links> --> |
| 223 | + |
| 224 | +</section> |
| 225 | + |
| 226 | +<!-- /.links --> |
| 227 | + |
0 commit comments