-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
Open
Harsh-Mathur-1503
wants to merge
75
commits into
stdlib-js:develop
Choose a base branch
from
Harsh-Mathur-1503:lcmf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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 | ||
|
||
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. | ||
|
||
--> | ||
|
||
# lcmf | ||
|
||
> Compute the [least common multiple][lcm] of two single-precision floating-point numbers. | ||
|
||
<!-- 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] (lcm) of two non-zero integers `a` and `b` is the smallest positive integer that is divisible by both `a` and `b`. The lcm is also known as the **lowest common multiple** or **smallest common multiple** and finds common use in calculating the **lowest common denominator** (lcd). | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var lcmf = require( '@stdlib/math/base/special/lcmf' ); | ||
``` | ||
|
||
### lcmf( a, b ) | ||
|
||
Computes the [least common multiple][lcm] for two single-precision floating-point numbers `a` and `b`. | ||
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
var v = lcmf( 10, 12 ); | ||
// returns 60 | ||
``` | ||
|
||
If either `a` or `b` is `0`, the function returns `0`. | ||
|
||
```javascript | ||
var v = lcmf( 0, 12 ); | ||
// returns 0 | ||
``` | ||
|
||
Both `a` and `b` must have integer values; otherwise, the function returns `NaN`. | ||
|
||
```javascript | ||
var v = lcmf( 3.14, 12 ); | ||
// returns NaN | ||
|
||
v = lcmf( NaN, 12 ); | ||
// 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 randu = require( '@stdlib/random/base/randu' ); | ||
var round = require( '@stdlib/math/base/special/round' ); | ||
var lcmf = require( '@stdlib/math/base/special/lcmf' ); | ||
|
||
var v; | ||
var i; | ||
|
||
for ( i = 0; i < 100; i++ ) { | ||
a = round( randu() * 50 ); | ||
b = round( randu() * 50 ); | ||
v = lcmf( a, b ); | ||
console.log( 'lcmf(%d,%d) = %d', a, b, 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( a, b ) | ||
|
||
Computes the [least common multiple][lcm] for two single-precision floating-point numbers `a` and `b`. | ||
|
||
```c | ||
float v = stdlib_base_lcmf( 10.0f, 12.0f ); | ||
// returns 60.0f | ||
``` | ||
|
||
The function accepts the following arguments: | ||
|
||
- **a**: `[in] float` input value. | ||
- **b**: `[in] float` input value. | ||
|
||
```c | ||
float stdlib_base_lcmf( const float a, const float b ); | ||
``` | ||
|
||
</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 ) { | ||
const float a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; | ||
const float b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; | ||
|
||
float out; | ||
int i; | ||
for (i = 0; i < 5; i++) { | ||
out = stdlib_base_lcmf( a[ i ], b[ i ] ); | ||
printf( "lcm(%f, %f) = %f\n", a[ i ], b[ i ], out ); | ||
} | ||
} | ||
``` | ||
|
||
</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"> | ||
|
||
</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> --> | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> | ||
|
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/** | ||
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/array/discrete-uniform' ); | ||
var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||
var pkg = require( './../package.json' ).name; | ||
var lcmf = require( './../lib' ); | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var x; | ||
var y; | ||
var z; | ||
var i; | ||
|
||
x = randu( 100, 0, 50 ); | ||
y = randu( 100, 0, 50 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = lcmf( x[ i % x.length ], y[ i % y.length ] ); | ||
if ( isnanf( z ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnanf( z ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
/** | ||
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/array/discrete-uniform' ); | ||
var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||
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 z; | ||
var i; | ||
|
||
x = randu( 100, 0, 50 ); | ||
y = randu( 100, 0, 50 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = lcmf( x[ i % x.length ], y[ i % y.length ] ); | ||
if ( isnanf( z ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnanf( z ) ) { | ||
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.