import Decimal from "break_infinity.js" ; import { Notation } from "./notation" ; const LEN = 23 ; const START = "\uE010" ; const START_HEX = START . codePointAt ( 0 ) || 65 ; const INFINITY = "\uE027" ; const NEGATIVE = "\uE028" ; const BLOBS = [ ] ; for ( let i = 0 ; i < LEN ; i ++ ) { const char = String . fromCharCode ( START_HEX + i ) ; BLOBS . push ( char ) ; } const LOG3 = Math . log10 ( 3 ) ; export class BlobsNotation extends Notation { public get name ( ) : string { return "Blobs" ; } public get infinite ( ) : string { return `${ INFINITY }` ; } public get negativeInfinite ( ) : string { return `${ NEGATIVE }${ INFINITY }` ; } public formatNegativeUnder1000 ( num ) { return `${ NEGATIVE }${ this . blobify ( new Decimal ( num - 1 ) ) }` ; } public formatNegativeDecimal ( num ) { return `${ NEGATIVE }${ this . blobify ( num . minus ( 1 ) ) }` ; } public formatUnder1000 ( num ) { return this . blobify ( new Decimal ( num ) ) ; } public formatDecimal ( num ) { return this . blobify ( num ) ; } protected blobify ( num ) { const number = this . reduceNumber ( num . abs ( ) ) ; if ( number < LEN ) { return BLOBS [ Math . floor ( number ) ] ; } if ( Math . floor ( number / LEN ) < LEN + 1 ) { return BLOBS [ Math . floor ( number / LEN ) - 1 ] + BLOBS [ Math . floor ( number % LEN ) ] ; } return this . blobify ( Decimal . floor ( number / LEN - 1 ) ) + BLOBS [ Math . floor ( number % LEN ) ] ; } protected reduceNumber ( num ) { if ( num . lte ( 1000 ) ) { return num . toNumber ( ) ; } return ( Math . log10 ( num . log10 ( ) ) - LOG3 ) / Math . log10 ( 1.0002 ) + 1000 ; } }