-
-
Notifications
You must be signed in to change notification settings - Fork 907
feat: add math/base/special/lcmf
#3096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
7d853de
feat: add math/base/special/lcmf
09d7f6c
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 dff1b9c
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 2130160
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 fe9f583
Merge branch 'stdlib-js:develop' into lcmf
Harsh-Mathur-1503 814abec
resolved the changes as requested
59090e1
resolved changes as requested
755782e
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 5fc950b
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 3f19612
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 d769d4e
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 0236db5
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 db63880
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 d233b45
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 d5e2ea1
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 a290354
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 246a763
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 30b5fa7
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 afef364
Update README.md
Harsh-Mathur-1503 0d18ce7
Updated examples
Harsh-Mathur-1503 7e2791e
Apply suggestions from code review
Harsh-Mathur-1503 ac50099
Apply suggestions from code review
Harsh-Mathur-1503 cf7a56a
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 913bc0f
Updated benchmark.js after review
Harsh-Mathur-1503 c8e6a51
Update benchmark.native.js after review
Harsh-Mathur-1503 5f8795b
Apply suggestions from code review
Harsh-Mathur-1503 7a88267
Update lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/be…
Harsh-Mathur-1503 5e5440d
Update benchmark.c
Harsh-Mathur-1503 77b4697
Update benchmark.c
Harsh-Mathur-1503 0a12704
Update repl.txt
Harsh-Mathur-1503 881bfd4
Update lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt
Harsh-Mathur-1503 de17576
Update README.md
Harsh-Mathur-1503 0c5e5d9
Update benchmark.js
Harsh-Mathur-1503 77e008a
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 8f59e2d
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 b34d9b3
Update main.c
Harsh-Mathur-1503 486a352
Update benchmark.js
Harsh-Mathur-1503 2400f97
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 ef7a4c9
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 99acace
Update main.c
Harsh-Mathur-1503 5beabf0
Update main.c
Harsh-Mathur-1503 9e602eb
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js
Harsh-Mathur-1503 1ffdfcd
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js
Harsh-Mathur-1503 03e4068
Update main.js
Harsh-Mathur-1503 cec3194
Update native.js
Harsh-Mathur-1503 7700ced
Update native.js
Harsh-Mathur-1503 5a3956f
Update main.js
Harsh-Mathur-1503 5316ae6
Update README.md
Harsh-Mathur-1503 de73acf
Update index.d.ts
Harsh-Mathur-1503 d196732
Update main.js
Harsh-Mathur-1503 8838682
Update test.js
Harsh-Mathur-1503 308353b
Update main.c
Harsh-Mathur-1503 5ae902b
Update test.native.js
Harsh-Mathur-1503 ef7fd65
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 76b8ae9
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 5b04e9d
Update lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/be…
Harsh-Mathur-1503 dcde939
Update benchmark.c
Harsh-Mathur-1503 6d7843d
Update test.ts
Harsh-Mathur-1503 d212d48
Update example.c
Harsh-Mathur-1503 d28ccce
Update index.js
Harsh-Mathur-1503 78bc3c2
Merge branch 'stdlib-js:develop' into lcmf
Harsh-Mathur-1503 352a99c
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js
Harsh-Mathur-1503 784cc9a
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js
Harsh-Mathur-1503 5bacf39
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/main.js
Harsh-Mathur-1503 691cfb8
Update manifest.json
Harsh-Mathur-1503 8f44972
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 209d798
Update lib/node_modules/@stdlib/math/base/special/lcmf/package.json
Harsh-Mathur-1503 ca16cf7
Update lib/node_modules/@stdlib/math/base/special/lcmf/package.json
Harsh-Mathur-1503 03f16b9
Update lib/node_modules/@stdlib/math/base/special/lcmf/package.json
Harsh-Mathur-1503 4b74121
Update lib/node_modules/@stdlib/math/base/special/lcmf/package.json
Harsh-Mathur-1503 ff495ab
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 9c39f1c
Merge branch 'stdlib-js:develop' into lcmf
Harsh-Mathur-1503 6f8f711
resolved conflicts
ea4b01c
Merge remote-tracking branch 'upstream/develop' into lcmf
stdlib-bot d3343c0
Update test.js
Harsh-Mathur-1503 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
227 changes: 227 additions & 0 deletions
227
lib/node_modules/@stdlib/math/base/special/lcmf/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
--> | ||
|
||
# lcmf | ||
|
||
> Compute the [least common multiple][lcm] of all integers from 1 up to a specified integer \( n \). | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
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. | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var lcmf = require( '@stdlib/math/base/special/lcmf' ); | ||
``` | ||
|
||
### lcmf(n) | ||
Computes the [least common multiple][lcm] for all integers from 1 up to n. | ||
|
||
```javascript | ||
var v = lcmf( 10 ); | ||
// returns 2520 | ||
``` | ||
|
||
If n is less than 1, the function returns 0. | ||
|
||
```javascript | ||
var v = lcmf( 0 ); | ||
// returns 0 | ||
|
||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
v = lcmf( -5 ); | ||
// returns 0 | ||
``` | ||
|
||
The input n must be an integer; otherwise, the function returns NaN. | ||
|
||
```javascript | ||
var v = lcmf( 3.14 ); | ||
// returns NaN | ||
|
||
v = lcmf( NaN ); | ||
// returns NaN | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var lcmf = require( '@stdlib/math/base/special/lcmf' ); | ||
|
||
var v; | ||
var i; | ||
|
||
for ( i = 1; i <= 10; i++ ) { | ||
v = lcmf( i ); | ||
console.log( 'lcm(1 to %d) = %d', i, v ); | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- C interface documentation. --> | ||
|
||
* * * | ||
|
||
<section class="c"> | ||
|
||
## C APIs | ||
|
||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- C usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
### Usage | ||
|
||
```c | ||
#include "stdlib/math/base/special/lcmf.h" | ||
``` | ||
|
||
### stdlib_base_lcmf( n ) | ||
|
||
Computes the [least common multiple][lcm] for all integers from 1 up to n. | ||
|
||
```c | ||
double v = stdlib_base_lcmf( 10 ); | ||
// returns 2520.0 | ||
``` | ||
|
||
The function accepts the following argument: | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- **n**: `[in] double` input value. | ||
|
||
```c | ||
double stdlib_base_lcmf( const double n ); | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- C API usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
### Examples | ||
|
||
```c | ||
#include "stdlib/math/base/special/lcmf.h" | ||
#include <stdio.h> | ||
|
||
int main( void ) { | ||
double v; | ||
int i; | ||
for ( i = 1; i <= 10; i++ ) { | ||
v = stdlib_base_lcmf( i ); | ||
printf( "lcm(1 to %d) = %lf\n", i, v ); | ||
} | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
</section> | ||
|
||
<!-- /.c --> | ||
|
||
<!-- 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. --> | ||
|
||
<section class="references"> | ||
|
||
</section> | ||
|
||
<!-- /.references --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
* * * | ||
|
||
## See Also | ||
|
||
- <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> | ||
|
||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[lcm]: https://en.wikipedia.org/wiki/Least_common_multiple | ||
|
||
<!-- <related-links> --> | ||
|
||
[@stdlib/math/base/special/gcd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gcd | ||
|
||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> | ||
|
53 changes: 53 additions & 0 deletions
53
lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved
Hide resolved
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var round = require( '@stdlib/math/base/special/round' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var pkg = require( './../package.json' ).name; | ||
var lcmf = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var x; | ||
var y; | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
x = round( randu() * 50.0 ); | ||
z = lcmf( x ); | ||
if ( isnan( z ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( z ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
60 changes: 60 additions & 0 deletions
60
lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.native.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var resolve = require( 'path' ).resolve; | ||
var bench = require( '@stdlib/bench' ); | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var tryRequire = require( '@stdlib/utils/try-require' ); | ||
var pkg = require( './../package.json' ).name; | ||
|
||
|
||
// VARIABLES // | ||
|
||
var lcmf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); | ||
var opts = { | ||
'skip': ( lcmf instanceof Error ) | ||
}; | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg+'::native', opts,function benchmark( b ) { | ||
var x; | ||
var y; | ||
var i; | ||
|
||
b.tic(); | ||
for( i = 0;i < b.iterations; i++ ) { | ||
x = ( randu() * 100.0 ) + 1.0; | ||
y = lcmf( x ); | ||
if( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.