All files main.js

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

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 1481x 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 3507x 503x 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 3507x 1x 1x 1x 1x 1x  
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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_log10.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-nan' );
var toWordf = require( '@stdlib/number/float32/base/to-word' );
var ABS_MASK = require( '@stdlib/constants/float32/abs-mask' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );
var FLOAT32_SIGNIFICAND_MASK = require( '@stdlib/constants/float32/significand-mask' );
var fromWordf = require( '@stdlib/number/float32/base/from-word' );
var kernelLog1pf = require( '@stdlib/math/base/special/kernel-log1pf' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
 
 
// VARIABLES //
 
var TWO25 = f32( 3.3554432000e+07 );          // 0x4c000000
var IVLN10HI = f32( 4.3432617188e-01 );       // 0x3ede6000
var IVLN10LO = f32( -3.1689971365e-05 );      // 0xb804ead9
var LOG10_2HI = f32( 3.0102920532e-01 );      // 0x3e9a2080
var LOG10_2LO = f32( 7.9034151668e-07 );      // 0x355427db
var HIGH_MAX_NORMAL_EXP = 0x7f800000|0;
var HIGH_MIN_NORMAL_EXP = 0x00800000|0;
var HIGH_BIASED_EXP_0 = 0x3f800000|0;
 
 
// MAIN //
 
/**
* Evaluates the common logarithm (base ten) for a single precision floating number.
*
* @param {NonNegativeNumber} 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 hx;
	var hi;
	var lo;
	var i;
	var k;
	var y;
	var r;
	var f;
 
	if ( isnanf( x ) || x < 0.0 ) {
		return NaN;
	}
	x = f32( x );
	hx = toWordf( x ) | 0;
	k = 0|0;
	if ( hx < HIGH_MIN_NORMAL_EXP ) {
		// Case: x < 2**-126
		if ( ( hx & ABS_MASK ) === 0 ) {
			return NINF;
		}
		k -= 25 | 0;
 
		// Subnormal number, scale up x:
		x = f32( x * TWO25 );
		hx = toWordf( x ) | 0;
	}
	if ( hx >= HIGH_MAX_NORMAL_EXP ) {
		return f32( x + x );
	}
	if ( hx === HIGH_BIASED_EXP_0 ) {
		return 0;
	}
	k = f32( k + f32( ( ( hx >> 23 ) - FLOAT32_EXPONENT_BIAS ) | 0 ) );
	hx &= FLOAT32_SIGNIFICAND_MASK;
	i = f32( ( ( hx + 0x4afb0d ) & HIGH_MAX_NORMAL_EXP ) | 0 );
 
	// Normalize x or x/2....
	x = fromWordf( hx | ( i ^ HIGH_BIASED_EXP_0 ) );
	k = f32( k + ( ( i >> 23 ) | 0 ) );
	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;
	hi = fromWordf( hx & 0xfffff000 );
	lo = f32( f32( f - hi ) - f32( hfsq ) + f32( r ) );
	return f32( f32( f32( y * LOG10_2LO ) + f32( f32( lo + hi ) * IVLN10LO ) + f32( lo * IVLN10HI ) + f32( hi * IVLN10HI ) + f32( y * LOG10_2HI ) ) ); // eslint-disable-line max-len
}
 
 
// EXPORTS //
 
module.exports = log10f;