diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c4305..1065885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,71 @@ > Package changelog. +
+ +## Unreleased (2024-08-23) + +
+ +### Packages + +
+ +#### [@stdlib/constants/float32/max-safe-nth-factorial](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float32/max-safe-nth-factorial) + +
+ +
+ +##### Features + +- [`8552f2c`](https://github.com/stdlib-js/stdlib/commit/8552f2c71db0996da51c6170dd9dc834ac74a43c) - add `constants/float32/max-safe-nth-factorial` [(#2821)](https://github.com/stdlib-js/stdlib/pull/2821) + +
+ + + +
+ +
+ + + +
+ + + +
+ +### Contributors + +A total of 2 people contributed to this release. Thank you to the following contributors: + +- Athan Reines +- Gunj Joshi + +
+ + + +
+ +### Commits + +
+ +- [`8552f2c`](https://github.com/stdlib-js/stdlib/commit/8552f2c71db0996da51c6170dd9dc834ac74a43c) - **feat:** add `constants/float32/max-safe-nth-factorial` [(#2821)](https://github.com/stdlib-js/stdlib/pull/2821) _(by Gunj Joshi, Athan Reines)_ + +
+ +
+ + + +
+ + +
## 0.3.1 (2024-08-18) diff --git a/README.md b/README.md index f77f500..ba70e44 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [npm-image]: http://img.shields.io/npm/v/@stdlib/constants.svg [npm-url]: https://npmjs.org/package/@stdlib/constants -[test-image]: https://github.com/stdlib-js/constants/actions/workflows/test.yml/badge.svg?branch=v0.3.1 -[test-url]: https://github.com/stdlib-js/constants/actions/workflows/test.yml?query=branch:v0.3.1 +[test-image]: https://github.com/stdlib-js/constants/actions/workflows/test.yml/badge.svg?branch=main +[test-url]: https://github.com/stdlib-js/constants/actions/workflows/test.yml?query=branch:main [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/constants/main.svg [coverage-url]: https://codecov.io/github/stdlib-js/constants?branch=main diff --git a/float32/max-safe-nth-factorial/README.md b/float32/max-safe-nth-factorial/README.md new file mode 100644 index 0000000..0e3ce21 --- /dev/null +++ b/float32/max-safe-nth-factorial/README.md @@ -0,0 +1,166 @@ + + +# FLOAT32_MAX_SAFE_NTH_FACTORIAL + +> Maximum safe nth [factorial][factorial] when stored in [single-precision floating-point][ieee754] format. + +
+ +## Usage + + + +```javascript +var FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-factorial' ); +``` + +#### FLOAT32_MAX_SAFE_NTH_FACTORIAL + +The maximum [safe][safe-integers] nth [factorial][factorial] when stored in [single-precision floating-point][ieee754] format. + + + +```javascript +var bool = ( FLOAT32_MAX_SAFE_NTH_FACTORIAL === 34 ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-factorial' ); + +function factorial( n ) { + var a; + var i; + + a = 1; + for ( i = 2; i <= n; i++ ) { + a *= i; + } + return a; +} + +var v; +var i; +for ( i = 0; i < 100; i++ ) { + v = factorial( i ); + if ( i > FLOAT32_MAX_SAFE_NTH_FACTORIAL ) { + console.log( 'Unsafe: %d', v ); + } else { + console.log( 'Safe: %d', v ); + } +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float32/max_safe_nth_factorial.h" +``` + +#### STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_FACTORIAL + +Macro for the maximum [safe][safe-integers] nth [factorial][factorial] when stored in [single-precision floating-point][ieee754] format. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + + + + + + + + + + diff --git a/float32/max-safe-nth-factorial/docs/repl.txt b/float32/max-safe-nth-factorial/docs/repl.txt new file mode 100644 index 0000000..882a27d --- /dev/null +++ b/float32/max-safe-nth-factorial/docs/repl.txt @@ -0,0 +1,13 @@ + +{{alias}} + Maximum safe nth factorial when stored in single-precision floating- + point format. + + Examples + -------- + > {{alias}} + 34 + + See Also + -------- + diff --git a/float32/max-safe-nth-factorial/docs/types/index.d.ts b/float32/max-safe-nth-factorial/docs/types/index.d.ts new file mode 100644 index 0000000..391ca6c --- /dev/null +++ b/float32/max-safe-nth-factorial/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/** +* Maximum safe nth factorial when stored in single-precision floating-point format. +* +* @example +* var max = FLOAT32_MAX_SAFE_NTH_FACTORIAL; +* // returns 34 +*/ +declare const FLOAT32_MAX_SAFE_NTH_FACTORIAL: number; + + +// EXPORTS // + +export = FLOAT32_MAX_SAFE_NTH_FACTORIAL; diff --git a/float32/max-safe-nth-factorial/docs/types/test.ts b/float32/max-safe-nth-factorial/docs/types/test.ts new file mode 100644 index 0000000..93554c5 --- /dev/null +++ b/float32/max-safe-nth-factorial/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @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. +*/ + +import FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT32_MAX_SAFE_NTH_FACTORIAL; // $ExpectType number +} diff --git a/float32/max-safe-nth-factorial/examples/index.js b/float32/max-safe-nth-factorial/examples/index.js new file mode 100644 index 0000000..d1cc892 --- /dev/null +++ b/float32/max-safe-nth-factorial/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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'; + +var FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( './../lib' ); // eslint-disable-line id-length + +function factorial( n ) { + var a; + var i; + + a = 1; + for ( i = 2; i <= n; i++ ) { + a *= i; + } + return a; +} + +var v; +var i; +for ( i = 0; i < 100; i++ ) { + v = factorial( i ); + if ( i > FLOAT32_MAX_SAFE_NTH_FACTORIAL ) { + console.log( 'Unsafe: %d', v ); + } else { + console.log( 'Safe: %d', v ); + } +} diff --git a/float32/max-safe-nth-factorial/include/stdlib/constants/float32/max_safe_nth_factorial.h b/float32/max-safe-nth-factorial/include/stdlib/constants/float32/max_safe_nth_factorial.h new file mode 100644 index 0000000..d4a95dc --- /dev/null +++ b/float32/max-safe-nth-factorial/include/stdlib/constants/float32/max_safe_nth_factorial.h @@ -0,0 +1,27 @@ +/** +* @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. +*/ + +#ifndef STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_FACTORIAL_H +#define STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_FACTORIAL_H + +/** +* Macro for the maximum safe nth factorial when stored in single-precision floating-point format. +*/ +#define STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_FACTORIAL 34 + +#endif // !STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_FACTORIAL_H diff --git a/float32/max-safe-nth-factorial/lib/index.js b/float32/max-safe-nth-factorial/lib/index.js new file mode 100644 index 0000000..3de5cdf --- /dev/null +++ b/float32/max-safe-nth-factorial/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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. +*/ + +/* eslint-disable id-length */ + +'use strict'; + +/** +* Maximum safe nth factorial when stored in single-precision floating-point format. +* +* @module @stdlib/constants/float32/max-safe-nth-factorial +* @type {integer} +* +* @example +* var FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( '@stdlib/constants/float32/max-safe-nth-factorial' ); +* // returns 34 +*/ + + +// MAIN // + +/** +* The maximum safe nth factorial when stored in single-precision floating-point format. +* +* @constant +* @type {integer} +* @default 34 +* @see [factorial]{@link https://en.wikipedia.org/wiki/Factorial} +* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} +*/ +var FLOAT32_MAX_SAFE_NTH_FACTORIAL = 34|0; // asm type annotation + + +// EXPORTS // + +module.exports = FLOAT32_MAX_SAFE_NTH_FACTORIAL; diff --git a/float32/max-safe-nth-factorial/manifest.json b/float32/max-safe-nth-factorial/manifest.json new file mode 100644 index 0000000..844d692 --- /dev/null +++ b/float32/max-safe-nth-factorial/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/float32/max-safe-nth-factorial/package.json b/float32/max-safe-nth-factorial/package.json new file mode 100644 index 0000000..4db45a0 --- /dev/null +++ b/float32/max-safe-nth-factorial/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/constants/float32/max-safe-nth-factorial", + "version": "0.0.0", + "description": "Maximum safe nth factorial when stored in single-precision floating-point format.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "constant", + "const", + "max", + "maximum", + "factorial", + "number", + "safe", + "integer", + "float", + "flt", + "floating", + "point", + "floating-point", + "float32", + "f32", + "ieee754" + ] +} diff --git a/float32/max-safe-nth-factorial/test/test.js b/float32/max-safe-nth-factorial/test/test.js new file mode 100644 index 0000000..b427779 --- /dev/null +++ b/float32/max-safe-nth-factorial/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 tape = require( 'tape' ); +var FLOAT32_MAX_SAFE_NTH_FACTORIAL = require( './../lib' ); // eslint-disable-line id-length + + +// TESTS // + +tape( 'main export is a number', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FLOAT32_MAX_SAFE_NTH_FACTORIAL, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'the exported value is 34', function test( t ) { + t.strictEqual( FLOAT32_MAX_SAFE_NTH_FACTORIAL, 34, 'returns expected value' ); + t.end(); +});