All files main.js

100% Statements 168/168
100% Branches 13/13
100% Functions 1/1
100% Lines 168/168

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 1691x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3507x 3x 3x 3504x 3504x 3504x 3504x 3504x 3507x 503x 2x 2x 501x 501x 501x 501x 501x 501x 3507x 1x 1x 3507x 1x 1x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3500x 3507x 1x 1x 1x 1x 1x  
/**
* @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.
*
*
* ## Notice
*
* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_log10f.c}. The implementation follows the original, but has been modified for JavaScript.
*
* ```text
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ```
*/
 
'use strict';
 
// MODULES //
 
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var toWordf = require( '@stdlib/number/float32/base/to-word' );
var fromWordf = require( '@stdlib/number/float32/base/from-word' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var ABS_MASK = require( '@stdlib/constants/float32/abs-mask' );
var FLOAT32_EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' );
var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );
var FLOAT32_SIGNIFICAND_MASK = require( '@stdlib/constants/float32/significand-mask' );
var kernelLog1pf = require( '@stdlib/math/base/special/kernel-log1pf' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
 
 
// VARIABLES //
 
// 2^25 = 33554432 => 0 10011000 00000000000000000000000 => 0x4c000000 = 1275068416
var TWO25 = f32( 3.3554432000e+07 );
 
// 1/ln(10) high part = 4.3432617188e-01 => 0 01111101 10111100110000000000000 => 0x3ede6000 = 1054760960
var IVLN10HI = f32( 4.3432617188e-01 );
 
// 1/ln(10) low part = -3.1689971365e-05 => 1 01110000 00001001110101011011001 => 0xb804ead9 = -1207637287
var IVLN10LO = f32( -3.1689971365e-05 );
 
// log10(2) high part = 3.0102920532e-01 => 0 01111101 00110100010000010000000 => 0x3e9a2080 = 1050288256
var LOG10_2HI = f32( 3.0102920532e-01 );
 
// log10(2) low part = 7.9034151668e-07 => 0 01101010 10101000010011111011011 => 0x355427db = 894707675
var LOG10_2LO = f32( 7.9034151668e-07 );
 
// 2**-126 => 0 00000001 00000000000000000000000 => 0x00800000 = 8388608
var MIN_NORMAL_WORD = 0x00800000|0; // asm type annotation
 
// 1.0 => 0 01111111 00000000000000000000000 => 0x3f800000 = 1065353216
var ONE_WORD = 0x3f800000|0; // asm type annotation
 
// Normalization offset:
var NORM_OFFSET = 0x4afb0d|0; // asm type annotation
 
// High word mask:
var HI_MASK = 0xfffff000|0; // asm type annotation
 
 
// MAIN //
 
/**
* Evaluates the common logarithm (base ten) of a single-precision floating-point number.
*
* @param {number} x - input value
* @returns {number} function value
*
* @example
* var v = log10f( 4.0 );
* // returns ~0.602
*
* @example
* var v = log10f( 8.0 );
* // returns ~0.903
*
* @example
* var v = log10f( 0.0 );
* // returns -Infinity
*
* @example
* var v = log10f( Infinity );
* // returns Infinity
*
* @example
* var v = log10f( NaN );
* // returns NaN
*
* @example
* var v = log10f( -4.0 );
* // returns NaN
*/
function log10f( x ) {
	var hfsq;
	var hi;
	var hx;
	var lo;
	var f;
	var i;
	var k;
	var r;
	var y;
 
	if ( isnanf( x ) || x < 0.0 ) {
		return NaN;
	}
	x = f32( x );
	hx = toWordf( x ) |0; // asm type annotation
	k = 0;
 
	// x < 2**-126
	if ( hx < MIN_NORMAL_WORD ) {
		if ( ( hx & ABS_MASK ) === 0 ) {
			return NINF;
		}
		k -= 25;
 
		// Subnormal number, scale up x:
		x = f32( x * TWO25 );
		hx = toWordf( x ) |0; // asm type annotation
	}
	if ( hx >= FLOAT32_EXPONENT_MASK ) {
		return f32( x + x );
	}
	if ( hx === ONE_WORD ) {
		return 0.0;
	}
	k += ( ( hx >> 23 ) - FLOAT32_EXPONENT_BIAS );
	hx &= FLOAT32_SIGNIFICAND_MASK;
	i = ( ( hx + NORM_OFFSET ) & MIN_NORMAL_WORD ) |0; // asm type annotation
 
	// Normalize x or x/2:
	x = fromWordf( hx | ( i ^ ONE_WORD ) );
	k += ( i >> 23 );
	y = f32( k );
	f = f32( x - 1.0 );
	hfsq = f32( 0.5 * f32( f * f ) );
	r = kernelLog1pf( f );
 
	hi = f32( f - hfsq );
	hx = toWordf( hi ) |0; // asm type annotation
	hi = fromWordf( hx & HI_MASK );
	lo = f32( f32( f - hi ) - hfsq + r );
	return f32( f32( y * LOG10_2LO ) + f32( f32( f32( lo + hi ) * IVLN10LO ) + f32( f32( lo * IVLN10HI ) + f32( f32( hi * IVLN10HI ) + f32( y * LOG10_2HI ) ) ) ) ); // eslint-disable-line max-len
}
 
 
// EXPORTS //
 
module.exports = log10f;