@@ -103,21 +103,23 @@ when defined(Posix) and not defined(genode):
103
103
{.passl : " -lm" .}
104
104
105
105
const
106
- PI * = 3.1415926535897932384626433 # # The circle constant PI (Ludolph's number)
107
- TAU * = 2.0 * PI # # The circle constant TAU (= 2 * PI)
108
- E* = 2.71828182845904523536028747 # # Euler's number
109
-
110
- MaxFloat64Precision * = 16 # # Maximum number of meaningful digits
111
- # # after the decimal point for Nim's
112
- # # ``float64`` type.
113
- MaxFloat32Precision * = 8 # # Maximum number of meaningful digits
114
- # # after the decimal point for Nim's
115
- # # ``float32`` type.
116
- MaxFloatPrecision * = MaxFloat64Precision # # Maximum number of
117
- # # meaningful digits
118
- # # after the decimal point
119
- # # for Nim's ``float`` type.
120
- RadPerDeg = PI / 180.0 # # Number of radians per degree
106
+ PI * = 3.1415926535897932384626433 # # The circle constant PI (Ludolph's number)
107
+ TAU * = 2.0 * PI # # The circle constant TAU (= 2 * PI)
108
+ E* = 2.71828182845904523536028747 # # Euler's number
109
+
110
+ MaxFloat64Precision * = 16 # # Maximum number of meaningful digits
111
+ # # after the decimal point for Nim's
112
+ # # ``float64`` type.
113
+ MaxFloat32Precision * = 8 # # Maximum number of meaningful digits
114
+ # # after the decimal point for Nim's
115
+ # # ``float32`` type.
116
+ MaxFloatPrecision * = MaxFloat64Precision # # Maximum number of
117
+ # # meaningful digits
118
+ # # after the decimal point
119
+ # # for Nim's ``float`` type.
120
+ MinFloatNormal * = 2.225073858507201 e-308 # # Smallest normal number for Nim's
121
+ # # ``float`` type. (= 2^-1022).
122
+ RadPerDeg = PI / 180.0 # # Number of radians per degree
121
123
122
124
type
123
125
FloatClass * = enum # # Describes the class a floating point value belongs to.
@@ -140,6 +142,7 @@ proc classify*(x: float): FloatClass =
140
142
doAssert classify (0.0 ) == fcZero
141
143
doAssert classify (0.3 / 0.0 ) == fcInf
142
144
doAssert classify (- 0.3 / 0.0 ) == fcNegInf
145
+ doAssert classify (5.0 e-324 ) == fcSubnormal
143
146
144
147
# JavaScript and most C compilers have no classify:
145
148
if x == 0.0 :
@@ -151,8 +154,9 @@ proc classify*(x: float): FloatClass =
151
154
if x > 0.0 : return fcInf
152
155
else : return fcNegInf
153
156
if x != x: return fcNan
157
+ if abs (x) < MinFloatNormal :
158
+ return fcSubnormal
154
159
return fcNormal
155
- # XXX: fcSubnormal is not detected!
156
160
157
161
proc isPowerOfTwo * (x: int ): bool {.noSideEffect .} =
158
162
# # Returns ``true``, if ``x`` is a power of two, ``false`` otherwise.
0 commit comments