const DOT_CHAR_CODE = 46 ; const ZERO_CHAR_CODE = 48 ; const NINE_CHAR_CODE = 57 ; export interface Operations < T extends number | bigint = number > { ZERO : T ; parse ( s , start ) : [ nextStart : number , value : T ] ; add ( a , b ) : T ; subtract ( a , b ) : T ; multiply ( a , b ) : T ; divide ( a , b ) : T ; } export const integerOperations = { ZERO : 0 , parse : ( s , start ) => { let result = 0 ; let i = start ; for ( ; i < s . length ; ++ i ) { const c = s . charCodeAt ( i ) ! ; if ( c < ZERO_CHAR_CODE || c > NINE_CHAR_CODE ) break ; result = result * 10 + c - ZERO_CHAR_CODE ; } return [ i , result ] ; } , add : ( a , b ) => a + b , subtract : ( a , b ) => a - b , multiply : ( a , b ) => a * b , divide : ( a , b ) => Math . floor ( a / b ) , } ; export const decimalOperations = { ZERO : 0 , parse : ( s , start ) => { let i = start ; let dotCnt = false ; for ( ; i < s . length ; ++ i ) { const c = s . charCodeAt ( i ) ! ; if ( c === DOT_CHAR_CODE ) { if ( dotCnt ) return [ - 1 , Number . NaN ] ; dotCnt = true ; continue ; } if ( c < ZERO_CHAR_CODE || c > NINE_CHAR_CODE ) break ; } return [ i , Number ( s . slice ( start , i ) ) ] ; } , add : ( a , b ) => a + b , subtract : ( a , b ) => a - b , multiply : ( a , b ) => a * b , divide : ( a , b ) => a / b , } ; export const bigintOperations = { ZERO : 0n , parse : ( s , start ) => { let i = start ; for ( ; i < s . length ; ++ i ) { const c = s . charCodeAt ( i ) ! ; if ( c < ZERO_CHAR_CODE || c > NINE_CHAR_CODE ) break ; } return [ i , BigInt ( s . slice ( start , i ) ) ] ; } , add : ( a , b ) => a + b , subtract : ( a , b ) => a - b , multiply : ( a , b ) => a * b , divide : ( a , b ) => a / b , } ;