From d0ebce3a1ed53532f2bee61096fa08400f534437 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Tue, 1 Oct 2024 10:36:29 +0530 Subject: [PATCH] feat: add `constants/float64/max-safe-nth-double-factorial` PR-URL: https://github.com/stdlib-js/stdlib/pull/2966 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines --- .../max-safe-nth-double-factorial/README.md | 166 ++++++++++++++++++ .../docs/repl.txt | 13 ++ .../docs/types/index.d.ts | 33 ++++ .../docs/types/test.ts | 28 +++ .../examples/index.js | 43 +++++ .../float64/max_safe_nth_double_factorial.h | 27 +++ .../lib/index.js | 49 ++++++ .../manifest.json | 36 ++++ .../package.json | 72 ++++++++ .../test/test.js | 38 ++++ 10 files changed, 505 insertions(+) create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/README.md create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/examples/index.js create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/include/stdlib/constants/float64/max_safe_nth_double_factorial.h create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/lib/index.js create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/manifest.json create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/package.json create mode 100644 lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/test/test.js diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/README.md b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/README.md new file mode 100644 index 00000000000..cad0305044c --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/README.md @@ -0,0 +1,166 @@ + + +# FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL + +> Maximum safe nth [double factorial][double-factorial] when stored in [double-precision floating-point][ieee754] format. + +
+ +## Usage + + + +```javascript +var FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-double-factorial' ); +``` + +#### FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL + +The maximum [safe][safe-integers] nth [double factorial][double-factorial] when stored in [double-precision floating-point][ieee754] format. + + + +```javascript +var bool = ( FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL === 301 ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-double-factorial' ); + +function factorial( n ) { + var a; + var i; + + a = 1; + for ( i = n; i >= 2; i -= 2 ) { + a *= i; + } + return a; +} + +var v; +var i; +for ( i = 0; i < 400; i++ ) { + v = factorial( i ); + if ( i > FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + console.log( 'Unsafe: %d', v ); + } else { + console.log( 'Safe: %d', v ); + } +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float64/max_safe_nth_double_factorial.h" +``` + +#### STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL + +Macro for the maximum [safe][safe-integers] nth [double factorial][double-factorial] when stored in [double-precision floating-point][ieee754] format. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/repl.txt b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/repl.txt new file mode 100644 index 00000000000..fbde931d3d0 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/repl.txt @@ -0,0 +1,13 @@ + +{{alias}} + Maximum safe nth double factorial when stored in double-precision floating- + point format. + + Examples + -------- + > {{alias}} + 301 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/index.d.ts new file mode 100644 index 00000000000..31003165281 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-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 double factorial when stored in double-precision floating-point format. +* +* @example +* var max = FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL; +* // returns 301 +*/ +declare const FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL: number; + + +// EXPORTS // + +export = FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL; diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/test.ts b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/docs/types/test.ts new file mode 100644 index 00000000000..becaf0614d4 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-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 FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL; // $ExpectType number +} diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/examples/index.js b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/examples/index.js new file mode 100644 index 00000000000..dc9d2bdf87e --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-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 FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( './../lib' ); // eslint-disable-line id-length + +function factorial( n ) { + var a; + var i; + + a = 1; + for ( i = n; i >= 2; i -= 2 ) { + a *= i; + } + return a; +} + +var v; +var i; +for ( i = 0; i < 400; i++ ) { + v = factorial( i ); + if ( i > FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL ) { + console.log( 'Unsafe: %d', v ); + } else { + console.log( 'Safe: %d', v ); + } +} diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/include/stdlib/constants/float64/max_safe_nth_double_factorial.h b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/include/stdlib/constants/float64/max_safe_nth_double_factorial.h new file mode 100644 index 00000000000..922f522cdad --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/include/stdlib/constants/float64/max_safe_nth_double_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_FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL +#define STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL + +/** +* Macro for the maximum safe nth double factorial when stored in double-precision floating-point format. +*/ +#define STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL 301 + +#endif // !STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL_H diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/lib/index.js b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/lib/index.js new file mode 100644 index 00000000000..65a8a7036f1 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/lib/index.js @@ -0,0 +1,49 @@ +/** +* @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'; + +/** +* Maximum safe nth double factorial when stored in double-precision floating-point format. +* +* @module @stdlib/constants/float64/max-safe-nth-double-factorial +* @type {integer} +* +* @example +* var FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = require( '@stdlib/constants/float64/max-safe-nth-double-factorial' ); +* // returns 301 +*/ + + +// MAIN // + +/** +* The maximum safe nth double factorial when stored in double-precision floating-point format. +* +* @constant +* @type {integer} +* @default 301 +* @see [double factorial]{@link https://en.wikipedia.org/wiki/Double_factorial} +* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985} +*/ +var FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL = 301|0; // eslint-disable-line id-length + + +// EXPORTS // + +module.exports = FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL; diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/manifest.json b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/manifest.json new file mode 100644 index 00000000000..844d692f643 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-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/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/package.json b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/package.json new file mode 100644 index 00000000000..5d3a1f593c9 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/constants/float64/max-safe-nth-double-factorial", + "version": "0.0.0", + "description": "Maximum safe nth double factorial when stored in double-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", + "double", + "dbl", + "floating", + "point", + "floating-point", + "float", + "float64", + "f64", + "ieee754" + ] +} diff --git a/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/test/test.js b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-factorial/test/test.js new file mode 100644 index 00000000000..f7a7b9101f8 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float64/max-safe-nth-double-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 FLOAT64_MAX_SAFE_NTH_DOUBLE_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 FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'the exported value is 301', function test( t ) { + t.strictEqual( FLOAT64_MAX_SAFE_NTH_DOUBLE_FACTORIAL, 301, 'returns expected value' ); + t.end(); +});