Skip to content

Commit 7ece9c1

Browse files
added fixtures
1 parent a62792a commit 7ece9c1

File tree

12 files changed

+126
-35
lines changed

12 files changed

+126
-35
lines changed

lib/node_modules/@stdlib/math/base/special/expf/lib/expmulti.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ var polyvalP = require( './polyval_p.js' );
7777
* @param {number} hi - upper bound
7878
* @param {number} lo - lower bound
7979
* @param {integer} k - power of 2
80+
* @param {integer} x - power of e
8081
* @returns {number} function value
8182
*/
8283
function expmulti( hi, lo, k ) {
8384
var r;
8485
var t;
8586
var c;
8687
var y;
88+
var twom100;
8789

90+
twom100 = 7.8886090522e-31;
8891
r = hi - lo;
8992
t = r * r;
90-
c = r - ( t*polyvalP( t ) );
93+
c = r - ( t*polyvalP( t ) );
9194
y = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi );
92-
93-
return ldexpf( y, k );
95+
if (k >= -125) {
96+
return ldexpf( y , k );
97+
} else {
98+
return ldexpf( y, k+100 ) * twom100 * twom100;
99+
}
94100
}
95101

96102

lib/node_modules/@stdlib/math/base/special/expf/lib/main.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,23 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
6868
var truncf = require( '@stdlib/math/base/special/truncf' );
6969
var NINF = require( '@stdlib/constants/float32/ninf' );
7070
var PINF = require( '@stdlib/constants/float32/pinf' );
71+
var absf = require( '@stdlib/math/base/special/absf' );
7172
var expmulti = require( './expmulti.js' );
7273

7374

7475
// VARIABLES //
7576

76-
var LN2_HI = 0.69314718;
77-
var LN2_LO = 1.90821484e-10;
78-
var LOG2_E = 1.44269504;
79-
var OVERFLOW = 88.3762626647949;
80-
var UNDERFLOW = -103.972084045410;
77+
var LN2_HI = [6.9314575195e-01, -6.9314575195e-01];
78+
var LN2_LO = [1.4286067653e-06, -1.4286067653e-06];
79+
var halF = [0.5, -0.5];
80+
var INVLN2 = 1.4426950216e+00;
81+
var OVERFLOW = 8.8721679688e+01;
82+
var UNDERFLOW = -1.0397208405e+02;
8183
var NEARZERO = 1.0 / (1 << 14);
8284
var NEG_NEARZERO = -NEARZERO;
8385

8486

87+
8588
// MAIN //
8689

8790
/**
@@ -165,13 +168,6 @@ var NEG_NEARZERO = -NEARZERO;
165168
*
166169
* ## Notes
167170
*
168-
* - According to an error analysis, the error is always less than \\(1\\) ulp (unit in the last place).
169-
*
170-
* - For an IEEE double,
171-
*
172-
* - if \\(x > 7.09782712893383973096\mbox{e+}02\\), then \\(e^{x}\\) overflows
173-
* - if \\(x < -7.45133219101941108420\mbox{e+}02\\), then \\(e^{x}\\) underflows
174-
*
175171
* - The hexadecimal values included in the source code are the intended ones for the used constants. Decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the intended hexadecimal values.
176172
*
177173
* @param {number} x - input value
@@ -197,6 +193,9 @@ function expf( x ) {
197193
var hi;
198194
var lo;
199195
var k;
196+
var xsb;
197+
198+
xsb = ( x < 0.0 ) ? 1 : 0;
200199

201200
if ( isnan( x ) || x === PINF ) {
202201
return x;
@@ -216,14 +215,11 @@ function expf( x ) {
216215
) {
217216
return 1.0 + x;
218217
}
219-
// Reduce and compute `r = hi - lo` for extra precision...
220-
if ( x < 0.0 ) {
221-
k = truncf( (LOG2_E*x) - 0.5 );
222-
} else {
223-
k = truncf( (LOG2_E*x) + 0.5 );
224-
}
225-
hi = x - (k*LN2_HI);
226-
lo = k * LN2_LO;
218+
// Argument reduction
219+
220+
k = truncf(INVLN2 * x + halF[xsb]);
221+
hi = x - k * LN2_HI[0];
222+
lo = k * LN2_LO[0];
227223

228224
return expmulti( hi, lo, k );
229225
}

lib/node_modules/@stdlib/math/base/special/expf/lib/polyval_p.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
* @returns {number} evaluated polynomial
3636
*/
3737
function evalpoly( x ) {
38+
var P1 = 1.6666625440e-1;
39+
var P2 = -2.7667332906e-3;
3840
if ( x === 0.0 ) {
39-
return 0.16666667;
41+
return P1;
4042
}
41-
return 0.16666667 + (x * (-0.0027777778 + (x * (0.00006613757 + (x * (-0.00000165339 + (x * 4.1381368e-8))))))); // eslint-disable-line max-len
43+
return P1 + x*P2 // eslint-disable-line max-len
4244
}
4345

4446
// EXPORTS //
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
julia 1.5
2+
JSON 0.21

lib/node_modules/@stdlib/math/base/special/expf/test/fixtures/julia/medium_negative_float32.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/expf/test/fixtures/julia/medium_positive_float32.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env julia
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2018 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
import JSON
20+
21+
"""
22+
gen( domain, filepath )
23+
24+
Generate fixture data and write to file.
25+
26+
# Arguments
27+
28+
* `domain`: domain
29+
* `filepath::AbstractString`: filepath of the output file
30+
31+
# Examples
32+
33+
``` julia
34+
julia> x = range( -100, stop = 100, length = 2001 );
35+
julia> gen( x, \"./data.json\" );
36+
```
37+
"""
38+
function gen( domain, filepath )
39+
x = collect( domain );
40+
y = exp.( x );
41+
data = Dict([
42+
("x", x),
43+
("expected", y)
44+
]);
45+
outfile = open( filepath, "w" );
46+
write( outfile, JSON.json(data) );
47+
write( outfile, "\n" );
48+
close( outfile );
49+
end
50+
51+
# Get the filename:
52+
file = @__FILE__;
53+
54+
# Extract the directory in which this file resides:
55+
dir = dirname( file );
56+
57+
# Medium negative values:
58+
x = Float32.(range( -88.721, stop = -0.3535, length = 1000 ));
59+
out = joinpath( dir, "./medium_negative_float32.json" );
60+
gen( x, out );
61+
62+
# Medium positive_float32 values:
63+
x = Float32.(range( 0.3535, stop = 88.721, length = 1000 ));
64+
out = joinpath( dir, "./medium_positive_float32.json" );
65+
gen( x, out );
66+
67+
# Small negative_float32 values:
68+
x = Float32.(range( -0.3535, stop = -2.0^-14, length = 1000 ));
69+
out = joinpath( dir, "./small_negative_float32.json" );
70+
gen( x, out );
71+
72+
# Small positive_float32 values:
73+
x = Float32.(range( 2.0^-14, stop = 0.3535, length = 1000 ));
74+
out = joinpath( dir, "./small_positive_float32.json" );
75+
gen( x, out );
76+
77+
# Tiny values:
78+
x = Float32.(range( -2.0^-14, stop = 2.0^-14, length = 1000 ));
79+
out = joinpath( dir, "./tiny_float32.json" );
80+
gen( x, out );

lib/node_modules/@stdlib/math/base/special/expf/test/fixtures/julia/small_negative_float32.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/expf/test/fixtures/julia/small_positive_float32.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/expf/test/fixtures/julia/tiny_float32.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)