From 57a3dba84b4350be2d7867cec655c653a6ac49ac Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sat, 18 May 2024 11:09:16 +0530 Subject: [PATCH] feat: add constants/float32/phi --- .../@stdlib/constants/float32/phi/README.md | 158 ++++++++++++++++++ .../constants/float32/phi/docs/repl.txt | 12 ++ .../float32/phi/docs/types/index.d.ts | 33 ++++ .../constants/float32/phi/docs/types/test.ts | 28 ++++ .../constants/float32/phi/examples/index.js | 24 +++ .../include/stdlib/constants/float32/phi.h | 27 +++ .../constants/float32/phi/lib/index.js | 53 ++++++ .../constants/float32/phi/manifest.json | 36 ++++ .../constants/float32/phi/package.json | 76 +++++++++ .../constants/float32/phi/test/test.js | 45 +++++ 10 files changed, 492 insertions(+) create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/README.md create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/examples/index.js create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/include/stdlib/constants/float32/phi.h create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/lib/index.js create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/manifest.json create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/package.json create mode 100644 lib/node_modules/@stdlib/constants/float32/phi/test/test.js diff --git a/lib/node_modules/@stdlib/constants/float32/phi/README.md b/lib/node_modules/@stdlib/constants/float32/phi/README.md new file mode 100644 index 000000000000..3ecb2169f619 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/README.md @@ -0,0 +1,158 @@ + + +# FLOAT32_PHI + +> [Golden ratio][phi]. + +
+ +The [golden ratio][phi] can be defined algebraically as + + + +```math +\phi = \frac{1 + \sqrt{5}}{2} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' ); +``` + +#### FLOAT32_PHI + +The [golden ratio][phi-value]. + +```javascript +var bool = ( FLOAT32_PHI === 1.6180340051651 ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' ); + +console.log( FLOAT32_PHI ); +// => 1.6180340051651 +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float32/phi.h" +``` + +#### STDLIB_CONSTANT_FLOAT32_PHI + +Macro for the [golden ratio][phi-value]. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/constants/float32/phi/docs/repl.txt b/lib/node_modules/@stdlib/constants/float32/phi/docs/repl.txt new file mode 100644 index 000000000000..e23884c63417 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/docs/repl.txt @@ -0,0 +1,12 @@ + +{{alias}} + Golden ratio. + + Examples + -------- + > {{alias}} + 1.6180340051651 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/constants/float32/phi/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float32/phi/docs/types/index.d.ts new file mode 100644 index 000000000000..17a9dbfe99ab --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/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 + +/** +* Golden ratio. +* +* @example +* var val = FLOAT32_PHI; +* // returns 1.6180340051651 +*/ +declare const FLOAT32_PHI: number; + + +// EXPORTS // + +export = FLOAT32_PHI; diff --git a/lib/node_modules/@stdlib/constants/float32/phi/docs/types/test.ts b/lib/node_modules/@stdlib/constants/float32/phi/docs/types/test.ts new file mode 100644 index 000000000000..bddcee6c48a9 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/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_PHI = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT32_PHI; // $ExpectType number +} diff --git a/lib/node_modules/@stdlib/constants/float32/phi/examples/index.js b/lib/node_modules/@stdlib/constants/float32/phi/examples/index.js new file mode 100644 index 000000000000..f003fc2099ca --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/examples/index.js @@ -0,0 +1,24 @@ +/** +* @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_PHI = require( './../lib' ); + +console.log( FLOAT32_PHI ); +// => 1.6180340051651 diff --git a/lib/node_modules/@stdlib/constants/float32/phi/include/stdlib/constants/float32/phi.h b/lib/node_modules/@stdlib/constants/float32/phi/include/stdlib/constants/float32/phi.h new file mode 100644 index 000000000000..3354c5fc1cfa --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/include/stdlib/constants/float32/phi.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_PHI_H +#define STDLIB_CONSTANTS_FLOAT32_PHI_H + +/** +* Macro for the golden ratio. +*/ +#define STDLIB_CONSTANT_FLOAT32_PHI 1.618033988749894848f + +#endif // !STDLIB_CONSTANTS_FLOAT32_PHI_H diff --git a/lib/node_modules/@stdlib/constants/float32/phi/lib/index.js b/lib/node_modules/@stdlib/constants/float32/phi/lib/index.js new file mode 100644 index 000000000000..c1a30f9d8917 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Golden ratio. +* +* @module @stdlib/constants/float32/phi +* @type {number} +* +* @example +* var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' ); +* // returns 1.6180340051651 +*/ + +// MODULES // + +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Golden ratio. +* +* @constant +* @type {number} +* @default 1.6180340051651 +* @see [OEIS]{@link http://oeis.org/A001622} +* @see [Wikipedia]{@link https://en.wikipedia.org/wiki/Golden_ratio} +*/ +var FLOAT32_PHI = float64ToFloat32( 1.61803398874989484820458683436563811772030917980576286213544862 ); // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = FLOAT32_PHI; diff --git a/lib/node_modules/@stdlib/constants/float32/phi/manifest.json b/lib/node_modules/@stdlib/constants/float32/phi/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/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/float32/phi/package.json b/lib/node_modules/@stdlib/constants/float32/phi/package.json new file mode 100644 index 000000000000..363e5e20ba1c --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/constants/float32/phi", + "version": "0.0.0", + "description": "Golden ratio.", + "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", + "mathematics", + "math", + "golden", + "ratio", + "phi", + "tau", + "golden mean", + "golden section", + "divine section", + "golden cut", + "medial section", + "divine proportion", + "golden number", + "number", + "divine", + "ieee754", + "single", + "floating-point", + "float32" + ] +} diff --git a/lib/node_modules/@stdlib/constants/float32/phi/test/test.js b/lib/node_modules/@stdlib/constants/float32/phi/test/test.js new file mode 100644 index 000000000000..56ca1af4c0fc --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/phi/test/test.js @@ -0,0 +1,45 @@ +/** +* @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 float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); +var FLOAT32_PHI = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a number', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FLOAT32_PHI, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'export is a double-precision floating-point number equal to 1.6180340051651', function test( t ) { + t.equal( FLOAT32_PHI, float64ToFloat32( 1.618033988749895 ), 'equals 1.6180340051651' ); + t.end(); +}); + +tape( 'the exported value equals ( 1 + sqrtf( 5 ) ) / 2', function test( t ) { + t.equal( FLOAT32_PHI, float64ToFloat32( float64ToFloat32( 1.0 + sqrtf( 5.0 ) ) / 2.0 ), 'equals ( 1 + sqrtf( 5 ) ) / 2' ); + t.end(); +});