@@ -12,8 +12,8 @@ import { Uncertainty } from '../datatypes/uncertainty';
1212
1313export const MAX_INT_VALUE = Math . pow ( 2 , 31 ) - 1 ;
1414export const MIN_INT_VALUE = Math . pow ( - 2 , 31 ) ;
15- export const MAX_LONG_VALUE = Math . pow ( 2 , 63 ) - 1 ;
16- export const MIN_LONG_VALUE = Math . pow ( - 2 , 63 ) ;
15+ export const MAX_LONG_VALUE = 9223372036854775807n ;
16+ export const MIN_LONG_VALUE = - 9223372036854775808n ;
1717export const MAX_FLOAT_VALUE = 99999999999999999999.99999999 ;
1818export const MIN_FLOAT_VALUE = - 99999999999999999999.99999999 ;
1919export const MIN_FLOAT_PRECISION_VALUE = Math . pow ( 10 , - 8 ) ;
@@ -53,8 +53,11 @@ export function overflowsOrUnderflows(value: any): boolean {
5353 if ( value . before ( MIN_DATE_VALUE ) ) {
5454 return true ;
5555 }
56+ } else if ( typeof value === 'bigint' ) {
57+ if ( ! isValidLong ( value ) ) {
58+ return true ;
59+ }
5660 } else if ( Number . isInteger ( value ) ) {
57- // TODO: Somehow distinguish Integer from Long
5861 if ( ! isValidInteger ( value ) ) {
5962 return true ;
6063 }
@@ -69,7 +72,7 @@ export function overflowsOrUnderflows(value: any): boolean {
6972}
7073
7174export function isValidInteger ( integer : any ) {
72- if ( isNaN ( integer ) ) {
75+ if ( ! Number . isInteger ( integer ) ) {
7376 return false ;
7477 }
7578 if ( integer > MAX_INT_VALUE ) {
@@ -82,7 +85,7 @@ export function isValidInteger(integer: any) {
8285}
8386
8487export function isValidLong ( long : any ) {
85- if ( isNaN ( long ) ) {
88+ if ( typeof long !== 'bigint' ) {
8689 return false ;
8790 }
8891 if ( long > MAX_LONG_VALUE ) {
@@ -98,6 +101,9 @@ export function isValidDecimal(decimal: any) {
98101 if ( isNaN ( decimal ) ) {
99102 return false ;
100103 }
104+ if ( typeof decimal !== 'number' ) {
105+ return false ;
106+ }
101107 if ( decimal > MAX_FLOAT_VALUE ) {
102108 return false ;
103109 }
@@ -129,7 +135,6 @@ export class OverFlowException extends Exception {}
129135export function successor ( val : any ) : any {
130136 if ( typeof val === 'number' ) {
131137 if ( Number . isInteger ( val ) ) {
132- // TODO: Somehow distinguish Integer from Long
133138 if ( val >= MAX_INT_VALUE ) {
134139 throw new OverFlowException ( ) ;
135140 } else {
@@ -142,6 +147,12 @@ export function successor(val: any): any {
142147 return val + MIN_FLOAT_PRECISION_VALUE ;
143148 }
144149 }
150+ } else if ( typeof val === 'bigint' ) {
151+ if ( val >= MAX_LONG_VALUE ) {
152+ throw new OverFlowException ( ) ;
153+ } else {
154+ return val + 1n ;
155+ }
145156 } else if ( val && val . isTime && val . isTime ( ) ) {
146157 if ( val . sameAs ( MAX_TIME_VALUE ) ) {
147158 throw new OverFlowException ( ) ;
@@ -182,7 +193,6 @@ export function successor(val: any): any {
182193export function predecessor ( val : any ) : any {
183194 if ( typeof val === 'number' ) {
184195 if ( Number . isInteger ( val ) ) {
185- // TODO: Somehow distinguish Integer from Long
186196 if ( val <= MIN_INT_VALUE ) {
187197 throw new OverFlowException ( ) ;
188198 } else {
@@ -195,6 +205,12 @@ export function predecessor(val: any): any {
195205 return val - MIN_FLOAT_PRECISION_VALUE ;
196206 }
197207 }
208+ } else if ( typeof val === 'bigint' ) {
209+ if ( val <= MIN_LONG_VALUE ) {
210+ throw new OverFlowException ( ) ;
211+ } else {
212+ return val - 1n ;
213+ }
198214 } else if ( val && val . isTime && val . isTime ( ) ) {
199215 if ( val . sameAs ( MIN_TIME_VALUE ) ) {
200216 throw new OverFlowException ( ) ;
@@ -234,12 +250,13 @@ export function predecessor(val: any): any {
234250
235251export function maxValueForInstance ( val : any ) {
236252 if ( typeof val === 'number' ) {
237- // TODO: Somehow distinguish Integer from Long
238253 if ( Number . isInteger ( val ) ) {
239254 return MAX_INT_VALUE ;
240255 } else {
241256 return MAX_FLOAT_VALUE ;
242257 }
258+ } else if ( typeof val === 'bigint' ) {
259+ return MAX_LONG_VALUE ;
243260 } else if ( val && val . isTime && val . isTime ( ) ) {
244261 return MAX_TIME_VALUE ?. copy ( ) ;
245262 } else if ( val && val . isDateTime ) {
@@ -284,12 +301,13 @@ export function maxValueForType(type: string, quantityInstance?: Quantity) {
284301
285302export function minValueForInstance ( val : any ) {
286303 if ( typeof val === 'number' ) {
287- // TODO: Somehow distinguish Integer from Long
288304 if ( Number . isInteger ( val ) ) {
289305 return MIN_INT_VALUE ;
290306 } else {
291307 return MIN_FLOAT_VALUE ;
292308 }
309+ } else if ( typeof val === 'bigint' ) {
310+ return MIN_LONG_VALUE ;
293311 } else if ( val && val . isTime && val . isTime ( ) ) {
294312 return MIN_TIME_VALUE ?. copy ( ) ;
295313 } else if ( val && val . isDateTime ) {
@@ -358,3 +376,10 @@ export function decimalAdjust(type: MathFn, value: any, exp: any) {
358376export function decimalOrNull ( value : any ) {
359377 return isValidDecimal ( value ) ? value : null ;
360378}
379+
380+ export function decimalLongOrNull ( value : any ) {
381+ return ( typeof value === 'number' && isValidDecimal ( value ) ) ||
382+ ( typeof value === 'bigint' && isValidLong ( value ) )
383+ ? value
384+ : null ;
385+ }
0 commit comments