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
702 changes: 702 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/log1p/scripts/accuracy.js

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/log1p/scripts/inputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

/*
* Generate the shared inputs which every fixture runner reads.
*
* ## Notes
*
* - Run with `node scripts/inputs.js` from the package directory. No fixture target discovers this script, as it is not under `test/fixtures/`.
* - For each regime, the script writes `test/fixtures/inputs/<regime>.json`. Every fixture runner reads its inputs from these files, and echoes them in its own output, so a misread input shows up when the output is scored.
* - Output is deterministic: every regime has its own recorded seed, and no timestamp is written, so rerunning the script reproduces each file byte for byte.
* - In the JSON files, finite values are written using JavaScript's number-to-string conversion (the shortest decimal which round-trips). As JSON has no representation for them, `NaN`, `+infinity`, and `-infinity` are written as the objects which `@stdlib/number/float64/to-json` returns (e.g., `{"type":"float64","value":"+Infinity"}`), which `@stdlib/number/float64/reviver` revives when a file is parsed. `-0` is written as `-0.0`, since `String( -0 )` drops the sign and `@stdlib/number/float64/to-json` returns `-0` unchanged; `JSON.parse` reads `-0.0` back as `-0`.
*/

/* eslint-disable n/no-sync */

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var mkdirSync = require( 'fs' ).mkdirSync;
var exists = require( '@stdlib/fs/exists' ).sync;
var writeFileSync = require( '@stdlib/fs/write-file' ).sync;
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
var ln = require( '@stdlib/math/base/special/ln' );
var exp = require( '@stdlib/math/base/special/exp' );
var abs = require( '@stdlib/math/base/special/abs' );
var max = require( '@stdlib/math/base/special/max' );
var min = require( '@stdlib/math/base/special/min' );
var pow = require( '@stdlib/math/base/special/pow' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
var SMALLEST_NORMAL = require( '@stdlib/constants/float64/smallest-normal' );
var SMALLEST_SUBNORMAL = require( '@stdlib/constants/float64/smallest-subnormal' );
var toJSON = require( '@stdlib/number/float64/to-json' );
var format = require( '@stdlib/string/format' );


// VARIABLES //

// Output directory:
var DIR = resolve( __dirname, '..', 'test', 'fixtures', 'inputs' );

// Number of variates per regime:
var N = 500;

// Base seed; regime `i` (in the order below) uses `SEED + i`:
var SEED = 20261031;

// A region is sampled log-uniformly (uniformly in the exponent) when its bounds have the same sign, neither is zero, and their magnitudes are more than this factor apart; otherwise, it is sampled uniformly:
var LOG_UNIFORM_RATIO = 10.0;

// The ten regimes of `log1p`'s existing Julia fixtures (`test/fixtures/julia/runner.jl`), with the same bounds:
var REGIMES = [
[ 'tiny_negative', -pow( 2.0, -54 ), 0.0 ],
[ 'tiny_positive', 0.0, pow( 2.0, -54 ) ],
[ 'small_negative', -pow( 2.0, -29 ), -pow( 2.0, -54 ) ],
[ 'small_positive', pow( 2.0, -54 ), pow( 2.0, -29 ) ],
[ 'medium_negative', -0.41422, -0.2929 ],
[ 'medium_positive', 0.2929, 0.41422 ],
[ 'large_negative', -0.9999, -0.41422 ],
[ 'large_positive', 0.41422, 100.0 ],
[ 'big_positive', pow( 2.0, 30 ), pow( 2.0, 52 ) ],
[ 'huge_positive', 1.0e200, 1.0e300 ]
];

// Edge cases, written in their own file:
var EDGE_CASES = [
NINF,
-FLOAT64_MAX,
-2.0,
-1.0 - pow( 2.0, -52 ), // largest double below -1
-1.0,
-1.0 + pow( 2.0, -53 ), // smallest double above -1
-1.0 + pow( 2.0, -52 ),
-1.0 + pow( 2.0, -51 ),
-SMALLEST_NORMAL,
-SMALLEST_SUBNORMAL * 2.0,
-SMALLEST_SUBNORMAL,
-0.0,
0.0,
SMALLEST_SUBNORMAL,
SMALLEST_SUBNORMAL * 2.0,
SMALLEST_NORMAL,
FLOAT64_MAX,
PINF,
NaN
];


// FUNCTIONS //

/**
* Serializes a double as a JSON value.
*
* @private
* @param {number} x - input value
* @returns {string} JSON value
*/
function serialize( x ) {
if ( isnan( x ) || x === PINF || x === NINF ) {
return JSON.stringify( toJSON( x ) );
}
if ( isNegativeZero( x ) ) {
return '-0.0';
}
return String( x );
}

/**
* Generates pseudorandom variates within a region.
*
* @private
* @param {number} lo - lower bound
* @param {number} hi - upper bound
* @param {NonNegativeInteger} n - number of variates
* @param {PositiveInteger} seed - PRNG seed
* @returns {Object} variates and a description of how they were drawn
*/
function variates( lo, hi, n, seed ) {
var dist;
var sign;
var rand;
var out;
var a;
var b;
var v;

rand = uniform({
'seed': seed
});
out = [];
if (
lo !== 0.0 &&
hi !== 0.0 &&
( lo < 0.0 ) === ( hi < 0.0 ) &&
( max( abs( lo ), abs( hi ) ) / min( abs( lo ), abs( hi ) ) ) >
LOG_UNIFORM_RATIO
) {
dist = 'log-uniform';
sign = ( lo < 0.0 ) ? -1.0 : 1.0;
a = ln( abs( lo ) );
b = ln( abs( hi ) );
if ( a > b ) {
v = a;
a = b;
b = v;
}
while ( out.length < n ) {
v = sign * exp( rand( a, b ) );

// Reject the rare variate which rounding pushes outside the region:
if ( v >= lo && v <= hi ) {
out.push( v );
}
}
} else {
dist = 'uniform';
while ( out.length < n ) {
out.push( rand( lo, hi ) );
}
}
return {
'x': out,
'distribution': dist,
'prng': rand.PRNG.NAME
};
}

/**
* Writes a shared input file.
*
* @private
* @param {string} name - regime name
* @param {NumberArray} x - input values
* @param {Object} meta - metadata
*/
function write( name, x, meta ) {
var json;
var i;

json = [];
for ( i = 0; i < x.length; i++ ) {
json.push( serialize( x[ i ] ) );
}
json = format( '{"regime":"%s","x":[%s],"meta":%s}\n', name, json.join( ',' ), JSON.stringify( meta ) );
writeFileSync( resolve( DIR, name+'.json' ), json );
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var seed;
var out;
var r;
var i;

if ( !exists( DIR ) ) {
mkdirSync( DIR );
}
for ( i = 0; i < REGIMES.length; i++ ) {
r = REGIMES[ i ];
seed = SEED + i;
out = variates( r[ 1 ], r[ 2 ], N, seed );
write( r[ 0 ], out.x, {
'generator': 'scripts/inputs.js',
'domain': [ r[ 1 ], r[ 2 ] ],
'distribution': out.distribution,
'prng': out.prng,
'seed': seed,
'n': out.x.length
});
}
write( 'edge_cases', EDGE_CASES, {
'generator': 'scripts/inputs.js',
'domain': null,
'distribution': 'hand-picked',
'prng': null,
'seed': null,
'n': EDGE_CASES.length
});
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2026 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.
#/


# VARIABLES #

ifndef VERBOSE
QUIET := @
else
QUIET :=
endif

# Specify the path to Cephes:
CEPHES ?=

# Specify a list of Cephes source files:
CEPHES_SRC ?=

# Specify the SHA-256 checksum of the Cephes double-precision archive, which identifies the Cephes version (Cephes has no version number of its own):
CEPHES_CHECKSUM ?= $(shell cat $(CEPHES)/../../checksums/moshier_cephes_double_zip/sha256 2>/dev/null)

# Determine the OS:
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
endif
endif
endif

# Define the program used for compiling C source files:
ifdef C_COMPILER
CC := $(C_COMPILER)
else
CC := gcc
endif

# Define the command-line options when compiling C files:
CFLAGS ?= \
-std=c99 \
-O3 \
-Wall \
-pedantic

# Determine whether to generate [position independent code][1]:
#
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
ifeq ($(OS), WINNT)
fPIC ?=
else
fPIC ?= -fPIC
endif

# List of C targets:
c_targets := runner.out


# TARGETS #

# Default target.
#
# This target is the default target.

all: $(c_targets)

.PHONY: all


# Compile C source.
#
# This target compiles C source files.

$(c_targets): %.out: %.c
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -DCEPHES_CHECKSUM='"$(CEPHES_CHECKSUM)"' -DRUNNER_CFLAGS='"$(strip $(CFLAGS))"' -o $@ $(CEPHES_SRC) $< -lm


# Generate test fixtures.
#
# This target generates test fixtures.

run: $(c_targets)
$(QUIET) ./$<

.PHONY: run


# Perform clean-up.
#
# This target removes generated files.

clean:
$(QUIET) -rm -f *.o *.out

.PHONY: clean


# Remove fixtures.
#
# This target removes fixture data.

clean-fixtures:
$(QUIET) -rm -f *.json

.PHONY: clean-fixtures

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"x":[{"type":"float64","value":"-Infinity"},-1.7976931348623157e+308,-2,-1.0000000000000002,-1,-0.99999999999999989,-0.99999999999999978,-0.99999999999999956,-2.2250738585072014e-308,-9.8813129168249309e-324,-4.9406564584124654e-324,-0,0,4.9406564584124654e-324,9.8813129168249309e-324,2.2250738585072014e-308,1.7976931348623157e+308,{"type":"float64","value":"+Infinity"},{"type":"float64","value":"NaN"}],"expected":[{"type":"float64","value":"NaN"},{"type":"float64","value":"NaN"},{"type":"float64","value":"NaN"},{"type":"float64","value":"NaN"},{"type":"float64","value":"-Infinity"},-36.736800569677101,-36.043653389117154,-35.350506208557213,-2.2250738585072014e-308,-9.8813129168249309e-324,-4.9406564584124654e-324,-0,0,4.9406564584124654e-324,9.8813129168249309e-324,2.2250738585072014e-308,709.78271289338397,{"type":"float64","value":"+Infinity"},{"type":"float64","value":"NaN"}],"meta":{"source":"c::cephes","function":"log1p","implementation":"Cephes' own log1p (double/unity.c): a rational approximation where 1+x is between 1/sqrt(2) and sqrt(2), and Cephes' log(1+x) elsewhere","versions":{"cephes":"moshier double.zip, sha256 c0b01a9593a1b12998e3d996120791cc71743ba025d42f4c6f838646c981f0b6"},"platform":{"os":"linux","arch":"x86_64","compiler":"gcc 15.3.0, -std=c99 -O3 -Wall -pedantic -ffp-contract=off","libc":"glibc 2.39"},"generated":"2026-11-19T13:51:41Z","inputs":"5283b7264b6fc109e9106b9202022b01d62c443b4d75be645cc3dfe26e929bb7","regime":"edge_cases"}}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading