import { BaseInfo32 , limbSize32 } from './BaseInfo32' ; /** Remove leading and trailing insignificant zero digits. */ export function trimNumber ( str ) { return ( str . replace ( /^(-?)0+([1-9a-z]|0(\.|$))/ , '$1$2' ) . replace ( /(\.|(\.[0-9a-z]*[1-9a-z]))0+$/ , '$2' ) ) ; } /** Output EXACT value of an IEEE 754 double in any base supported by Number.toString.
     * Exponent must be between -2 and 61, and last 3 bits of mantissa must be 0.
    * Useful for debugging. */ export function numberToString ( dbl , base = 10 ) { let { pad , limbBase } = BaseInfo32 . init ( base ) ; let sign = '' ; let out = '' ; let limb ; let limbStr ; if ( isNaN ( dbl ) ) return ( 'NaN' ) ; if ( dbl < 0 ) { sign = '-' ; dbl = - dbl ; } if ( ! isFinite ( dbl ) ) return ( sign + 'Inf' ) ; if ( dbl < 1 ) { out += '0' ; } else { let iPart = Math . floor ( dbl ) ; dbl -= iPart ; while ( iPart ) { limb = iPart % limbBase ; iPart = ( iPart - limb ) / limbBase ; limbStr = limb . toString ( base ) ; out = limbStr + out ; if ( iPart ) out = pad . substr ( limbStr . length ) + out ; } } if ( dbl > 0 ) { out += '.' ; if ( limbBase != limbSize32 ) { limbBase = base ; pad = '' ; } while ( dbl ) { dbl *= limbBase ; limb = dbl >>> 0 ; dbl -= limb ; limbStr = limb . toString ( base ) ; out += pad . substr ( limbStr . length ) + limbStr ; } } return ( sign + out . replace ( /(\.[0-9a-z]*[1-9a-z])0+$/ , '$1' ) ) ; }