@@ -67,32 +67,38 @@ proc strToFp128*(s: string): Int128 =
67
67
for i in 0 ..< len (frac):
68
68
exponent *= i128 (10 )
69
69
# we shift in two steps to avoid shaving off the MSBs
70
- ((frac.parseInt128 () shl (SCALE div 2 )) div exponent) shl ( SCALE div 2 )
70
+ ((frac.parseInt128 () shl (SCALE - 2 )) div exponent) shl 2
71
71
else :
72
72
i128 (0 )
73
73
74
74
let absresult = whole.parseInt128 shl SCALE + fraction
75
75
if negative: - absresult: else : absresult
76
76
77
77
proc test () =
78
- let negpi = cast [UInt128 ](strToFp128 (" -3.14159265359" ))
78
+ let
79
+ negpi_str = " -3.1415926535897932384"
80
+ negpi = cast [UInt128 ](strToFp128 (negpi_str))
79
81
echo negpi.toHex ()
80
82
echo cast [UInt128 ](strToFp128 (" -1" )).toHex ()
81
83
echo cast [UInt128 ](strToFp128 (" 1" )).toHex ()
82
84
echo cast [UInt128 ](strToFp128 (" 1.25" )).toHex ()
83
85
echo cast [UInt128 ](strToFp128 (" 1.32" )).toHex ()
84
86
echo " 998877665544332211"
85
87
88
+ echo negpi_str
86
89
echo fp128ToStr (cast [Int128 ](negpi))
90
+
87
91
echo fp128ToStr (strToFp128 (" -1" ))
88
92
echo fp128ToStr (strToFp128 (" 1" ))
89
93
echo fp128ToStr (strToFp128 (" 1.25" ))
90
94
echo fp128ToStr (strToFp128 (" 1.32" ))
91
95
echo fp128ToStr (strToFp128 (" 1.3333333333333333333" ))
92
- echo fp128ToStr (strToFp128 (" 0.0000000000000000001 " ))
93
- echo fp128ToStr (i128 (1 ))
96
+ echo fp128ToStr (strToFp128 (" 0.000000000000000001 " ))
97
+ echo " smallest possible: \n " , fp128ToStr (i128 (1 ))
94
98
echo fp128ToStr (strToFp128 (" " ))
95
- echo fp128ToStr (strToFp128 (" -0.95908709673676639795" ))
99
+ let hi_bit_number = " -0.95908709673676639795"
100
+ echo hi_bit_number
101
+ echo fp128ToStr (strToFp128 (hi_bit_number))
96
102
97
103
# test()
98
104
# quit()
0 commit comments