Skip to content
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

feat: add math/base/special/lcmf #3096

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7d853de
feat: add math/base/special/lcmf
Nov 11, 2024
09d7f6c
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
dff1b9c
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
2130160
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
fe9f583
Merge branch 'stdlib-js:develop' into lcmf
Harsh-Mathur-1503 Nov 12, 2024
814abec
resolved the changes as requested
Nov 12, 2024
59090e1
resolved changes as requested
Nov 12, 2024
755782e
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
5fc950b
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
3f19612
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
d769d4e
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
0236db5
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
db63880
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
d233b45
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
d5e2ea1
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
a290354
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
246a763
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
30b5fa7
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
afef364
Update README.md
Harsh-Mathur-1503 Nov 12, 2024
0d18ce7
Updated examples
Harsh-Mathur-1503 Nov 12, 2024
7e2791e
Apply suggestions from code review
Harsh-Mathur-1503 Nov 12, 2024
ac50099
Apply suggestions from code review
Harsh-Mathur-1503 Nov 12, 2024
cf7a56a
Update lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Harsh-Mathur-1503 Nov 12, 2024
913bc0f
Updated benchmark.js after review
Harsh-Mathur-1503 Nov 12, 2024
c8e6a51
Update benchmark.native.js after review
Harsh-Mathur-1503 Nov 12, 2024
5f8795b
Apply suggestions from code review
Harsh-Mathur-1503 Nov 12, 2024
7a88267
Update lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/c/be…
Harsh-Mathur-1503 Nov 12, 2024
5e5440d
Update benchmark.c
Harsh-Mathur-1503 Nov 12, 2024
77b4697
Update benchmark.c
Harsh-Mathur-1503 Nov 12, 2024
0a12704
Update repl.txt
Harsh-Mathur-1503 Nov 12, 2024
881bfd4
Update lib/node_modules/@stdlib/math/base/special/lcmf/docs/repl.txt
Harsh-Mathur-1503 Nov 12, 2024
de17576
Update README.md
Harsh-Mathur-1503 Nov 12, 2024
0c5e5d9
Update benchmark.js
Harsh-Mathur-1503 Nov 12, 2024
77e008a
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 Nov 12, 2024
8f59e2d
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 Nov 12, 2024
b34d9b3
Update main.c
Harsh-Mathur-1503 Nov 12, 2024
486a352
Update benchmark.js
Harsh-Mathur-1503 Nov 12, 2024
2400f97
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 Nov 12, 2024
ef7a4c9
Update lib/node_modules/@stdlib/math/base/special/lcmf/src/main.c
Harsh-Mathur-1503 Nov 12, 2024
99acace
Update main.c
Harsh-Mathur-1503 Nov 12, 2024
5beabf0
Update main.c
Harsh-Mathur-1503 Nov 12, 2024
9e602eb
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js
Harsh-Mathur-1503 Nov 12, 2024
1ffdfcd
Update lib/node_modules/@stdlib/math/base/special/lcmf/lib/native.js
Harsh-Mathur-1503 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 225 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/lcmf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<!--

@license Apache-2.0

Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved Hide resolved
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 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 = lcm( a, b );
console.log( 'lcmf(%d,%d) = %d', a, b, v );
}
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved Hide resolved
```

</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 = lcmf(a[i], b[i]);
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved Hide resolved
printf("lcm(%f, %f) = %f\n", a[i], b[i], out);
Harsh-Mathur-1503 marked this conversation as resolved.
Show resolved Hide resolved
}
}
```

</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 -->

108 changes: 108 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/lcmf/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
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' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var z;
var i;
/**
* @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' );


// MAIN //

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();
});

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();
});
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();
});
Loading
Loading