import BigNumber , { bn } from '../big-number' ; export const ZERO = bn ( 0 ) ; export const ONE = bn ( 1 ) ; export const TWO = bn ( 2 ) ; export const abs = ( a , b ) : BigNumber => { return a . gt ( 0 ) ? a : a . negated ( ) ; } ; export const add = ( a , b ) : BigNumber => { return a . plus ( b ) ; } ; export const sub = ( a , b ) : BigNumber => { if ( b . gt ( a ) ) { throw new Error ( 'SUB_OVERFLOW' ) ; } return a . minus ( b ) ; } ; export const max = ( a , b ) : BigNumber => { return a . gte ( b ) ? a : b ; } ; export const min = ( a , b ) : BigNumber => { return a . lt ( b ) ? a : b ; } ; export const mul = ( a , b ) : BigNumber => { return a . times ( b ) ; } ; export const div = ( a , b , roundUp ) : BigNumber => { return roundUp ? divUp ( a , b ) : divDown ( a , b ) ; } ; export const divDown = ( a , b ) : BigNumber => { if ( b . isZero ( ) ) { throw new Error ( 'ZERO_DIVISION' ) ; } return a . idiv ( b ) ; } ; export const divUp = ( a , b ) : BigNumber => { if ( b . isZero ( ) ) { throw new Error ( 'ZERO_DIVISION' ) ; } return a . isZero ( ) ? ZERO : ONE . plus ( a . minus ( ONE ) . idiv ( b ) ) ; } ;