What
Code: Select all
; #MYCONST = BIGNUM <> ValD("#MYCONST")
; https://www.purebasic.fr/english/viewtopic.php?t=79180
#PB_MAX_Float = 3.4028234663852886e38
#PB_MIN_Float = 1.1754943508222875e-38 ; (normalized)
#PB_LOW_Float = 1.4012984643248171e-45 ; (denormalized)
#PB_ESPILON_Float = 1.1920928955078125e-7
#PB_MAX_Double = 1.7976931348623157081e308
#PB_MIN_Double = 2.2250738585072013831e-308 ; (normalized)
#PB_LOW_Double = 4.9406564584124654418e-324 ; (denormalized)
#PB_EPSILON_Double = 2.2204460492503130808e-16
#nNull = -999.00000000000000000
#small1 = 1e-16 ; Epsilon value: small '1' to add to double calcs to round up or prevent overflows.
#small1_EQ = 1e-9 ; Epsilon value: small '1' for IsEqual comparisons
;#TE_OVERFLOW = 9.900000000000000000E37
;#TE_OVERFLOW = ValD("9.9e37") = 98999999999999993000000000000000000000.0
#TE_OVERFLOW = 98999999999999993e21;000000000000000000000.0
Macro IsEqual(x, y, small1=#small1_EQ)
Bool(Abs((x)-(y)) <= small1)
EndMacro
;-{ TEST
Structure TD
i.i
x.d
EndStructure
Procedure.i isOVERFLOW_REAL(r$, *d.TD) ;-! Simulate function acting on very large number
*d\x = ValD(r$)
If *d\x >= #TE_OVERFLOW ;9.9+37
*d\x = #nNull
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure.i isOVERFLOW_REALeq(r$, *d.TD) ;-! Simulate function acting on very large number
*d\x = ValD(r$)
If IsEqual(*d\x, #TE_OVERFLOW);9.9+37
*d\x = #nNull
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Global r.TD, r2.TD, r3.TD
Global.i rs = 24
Global r$, TEO$ = "9.900000000000000000E37"
;-! Case 1: Overflow inequalities
r$ = "9.9e+37"
Debug "Case 1: isOverflow? " + r$ + " >= " + TEO$ + " FAIL."
Debug "Case 1: isOverflow should be 1."
Debug "Case 1: REAL Overflow -> " + Str(isOVERFLOW_REAL(r$, @r))
Debug "Case 1: REAL Overflow~-> " + Str(isOVERFLOW_REALeq(r$, @r))
Debug "~~~"
r$ = "9.9e+36"
Debug "Case 2: isOverflow? " + r$ + " >= " + TEO$ + " OK."
Debug "Case 2: isOverflow should be 0."
Debug "Case 2: REAL Overflow -> " + Str(isOVERFLOW_REAL(r$, @r))
Debug "Case 2: REAL Overflow~-> " + Str(isOVERFLOW_REALeq(r$, @r))
Debug "~~~"
r$ = "9.9e+3"
Debug "Case 3: isOverflow? " + r$ + " >= " + TEO$ + " OK."
Debug "Case 3: isOverflow should be 0."
Debug "Case 3: REAL Overflow -> " + Str(isOVERFLOW_REAL(r$, @r))
Debug "Case 3: REAL Overflow~-> " + Str(isOVERFLOW_REALeq(r$, @r))
Debug "~~~"
r$ = "9.9e+37"
r\x = 9.9e37
r2\x = 9.9000000000000000000e37
Debug "Case 4: Large Diff? (" + r$ + " - " + TEO$ + ") OK." ;-! Case 4: Large Diff
Debug "r = " + LSet(StrD(r\x,16),rs+16)
Debug "r2 = " + LSet(StrD(r2\x,16),rs+16)
Debug "r-r2 = " + LSet(StrD(r\x - r2\x,16),rs)
Debug "~~~"
#SOMECONST = 9.9e21
r$ = StrD(9.9e21,16)
r2$ = StrD(#SOMECONST,16)
Debug "Case 4: Small Diff? (" + r$ + " - " + r2$ + ") OK." ;-! Case 4: Small Diff
Debug "r = " + LSet(StrD(r\x,16),rs+16)
Debug "r2 = " + LSet(StrD(r2\x,16),rs+16)
Debug "r-r2 = " + LSet(StrD(r\x - r2\x,16),rs)
Debug "~~~ DONE ~~~"
#MY_CONST = 9.9e37
r$ = "9.9e37"
Debug "9.9e37 = " + LSet(StrD(ValD(r$),16),rs)
Debug "#9.9e37 = " + LSet(StrD(#MY_CONST,16),rs)
Debug "DIFF = " + LSet(StrD(ValD(r$) - #MY_CONST,16),rs)
;-} TEST