Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -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.
*/

#ifndef STDLIB_MATH_BASE_SPECIAL_EXP2F_H
#define STDLIB_MATH_BASE_SPECIAL_EXP2F_H

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Evaluates the base `2` exponential function (single-precision).
*/
float stdlib_base_exp2f( const float x );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_SPECIAL_EXP2F_H
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/exp2f/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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';

/**
* Evaluate the base `2` exponential function (single-precision).
*
* @module @stdlib/math/base/special/exp2f
*
* @example
* var exp2f = require( '@stdlib/math/base/special/exp2f' );
*
* var v = exp2f( 3.0 );
* // returns 8.0
*
* v = exp2f( -9.0 );
* // returns ~0.002
*
* v = exp2f( 0.0 );
* // returns 1.0
*
* v = exp2f( NaN );
* // returns NaN
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
125 changes: 125 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/exp2f/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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.
*
* ## Notice
*
* The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes}. The implementation follows the original, but has been modified for JavaScript.
*
* ```text
* Copyright 1984, 1995, 2000 by Stephen L. Moshier
*
* Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee.
*
* Stephen L. Moshier
* moshier@na-net.ornl.gov
* ```
*/

'use strict';

// TODO: replace with TOMS (Openlibm) algo (updating license header and long comment)

Check warning on line 34 in lib/node_modules/@stdlib/math/base/special/exp2f/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: replace with TOMS (Openlibm) algo...'

// MODULES //

var FLOAT32_MAX_BASE2_EXPONENT = require( '@stdlib/constants/float32/max-base2-exponent' ); // eslint-disable-line id-length
var FLOAT32_MIN_BASE2_EXPONENT = require( '@stdlib/constants/float32/min-base2-exponent' ); // eslint-disable-line id-length
var roundf = require( '@stdlib/math/base/special/roundf' );
var ldexpf = require( '@stdlib/math/base/special/ldexpf' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var polyvalP = require( './polyval_p.js' );
var polyvalQ = require( './polyval_q.js' );


// MAIN //

/**
* Evaluates the base `2` exponential function (single-precision).
*
* ## Method
*
* - Range reduction is accomplished by separating the argument into an integer \\( k \\) and fraction \\( f \\) such that
*
* ```tex
* 2^x = 2^k 2^f
* ```
*
* - A Pade' approximate
*
* ```tex
* 1 + 2x \frac{\mathrm{P}\left(x^2\right)}{\mathrm{Q}\left(x^2\right) - x \mathrm{P}\left(x^2\right)}
* ```
*
* approximates \\( 2^x \\) in the basic range \\( \[-0.5, 0.5] \\).
*
* ## Notes
*
* - Relative error:
*
* | arithmetic | domain | # trials | peak | rms |
* |:----------:|:-----------:|:--------:|:-------:|:-------:|
* | IEEE | -1022,+1024 | 30000 | 1.8e-16 | 5.4e-17 |
*
* @param {number} x - input value
* @returns {number} function value
*
* @example
* var v = exp2f( 3.0 );
* // returns 8.0
*
* @example
* var v = exp2f( -9.0 );
* // returns ~0.002
*
* @example
* var v = exp2f( 0.0 );
* // returns 1.0
*
* @example
* var v = exp2f( NaN );
* // returns NaN
*/
function exp2f( x ) {
var px;
var xx;
var n;
if ( isnanf( x ) ) {
return x;
}
if ( x > FLOAT32_MAX_BASE2_EXPONENT ) {
return PINF;
}
if ( x < FLOAT32_MIN_BASE2_EXPONENT ) {
return 0.0;
}
// Separate into integer and fractional parts...
n = roundf( x );
x -= n;

xx = x * x;
px = x * polyvalP( xx );
x = px / ( polyvalQ( xx ) - px );
x = 1.0 + ldexpf( x, 1 );

// Scale by power of 2:
return ldexpf( x, n );
}


// EXPORTS //

module.exports = exp2f;
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/exp2f/lib/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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 addon = require( './../src/addon.node' );


// MAIN //

/**
* Evaluates the base `2` exponential function (single-precision).
*
* @private
* @param {number} x - input value
* @returns {number} function value
*/
function exp2f( x ) {
return addon( x );
}


// EXPORTS //

module.exports = exp2f;
47 changes: 47 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/exp2f/lib/polyval_p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @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.
*/

/* This is a generated file. Do not edit directly. */
'use strict';

// MAIN //

/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @private
* @param {number} x - value at which to evaluate the polynomial
* @returns {number} evaluated polynomial
*/
function evalpoly( x ) {
if ( x === 0.0 ) {
return 1513.906801156151;
}
return 1513.906801156151 + (x * (20.202065669316532 + (x * 0.023093347705734523))); // eslint-disable-line max-len
}


// EXPORTS //

module.exports = evalpoly;
47 changes: 47 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/exp2f/lib/polyval_q.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @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.
*/

/* This is a generated file. Do not edit directly. */
'use strict';

// MAIN //

/**
* Evaluates a polynomial.
*
* ## Notes
*
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @private
* @param {number} x - value at which to evaluate the polynomial
* @returns {number} evaluated polynomial
*/
function evalpoly( x ) {
if ( x === 0.0 ) {
return 4368.211668792106;
}
return 4368.211668792106 + (x * (233.1842117223149 + (x * 1.0)));
}


// EXPORTS //

module.exports = evalpoly;
Loading
Loading