--- a/Float.st Tue Dec 03 15:33:40 2019 +0100
+++ b/Float.st Tue Dec 03 19:03:15 2019 +0100
@@ -124,8 +124,11 @@
*/
# ifndef isnan
# define isnan(x) \
- ((((unsigned int *)(&x))[0] == 0x00000000) && \
- (((unsigned int *)(&x))[1] == 0xFFF80000))
+ ((((unsigned int *)(&x))[1] & 0x7F800000) == 0x7F800000)
+// old, invalid definition
+// # define isnan(x) \
+// ((((unsigned int *)(&x))[0] == 0x00000000) && \
+// (((unsigned int *)(&x))[1] == 0xFFF80000))
# endif
# ifndef isPositiveInfinity
@@ -693,22 +696,35 @@
NaN isNil ifTrue:[
%{
-#if defined(LINUX) && defined(__i386__)
-# ifdef NAN
- @global(Float:NaN) = __MKFLOAT(NAN);
+#ifdef NAN
+ @global(Float:NaN) = __MKFLOAT(NAN);
+#else
+# if defined(LINUX) && defined(__i386__)
+ @global(Float:NaN) = __MKFLOAT(_SNAN);
# else
- @global(Float:NaN) = __MKFLOAT(_SNAN);
+# if defined(__i386__) || defined(__x86_64__)
+ {
+ union {
+ double d;
+ int i[2];
+ } u;
+ u.i[0] = 0;
+ u.i[1] = 0x7FF80000;
+ @global(Float:NaN) = __MKFLOAT(u.d);
+ }
+# endif
# endif
#endif
%}.
- NaN isNil ifTrue:[
- NaN := super NaN.
- ].
+ NaN isNil ifTrue:[
+ NaN := super NaN.
+ ].
].
^ NaN
- "
+ "NaN := nil
Float NaN
+ Float NaN negated
Float NaN + 0.0
Float NaN + Float NaN
0.0 + Float NaN
@@ -3653,6 +3669,37 @@
"
!
+integerAndFractionParts
+ "return the integer and the fraction part of the receiver as a pair
+ of flaots (i.e. the result of the modf function)"
+
+ |integerPart fractionPart|
+
+%{
+#ifdef __SCHTEAM__
+ ERROR("unimplemented");
+#else
+ double dVal, iPart, fPart;
+ OBJ i, f;
+
+ dVal = __floatVal(self);
+ fPart = modf(dVal, &iPart);
+ __qMKFLOAT(i, iPart);
+ __qMKFLOAT(f, fPart);
+ integerPart = i;
+ fractionPart = f;
+#endif
+%}.
+ ^ { integerPart . fractionPart }
+
+ "
+ 0.5 integerAndFractionParts
+ -0.5 integerAndFractionParts
+ 12345.6789 integerAndFractionParts
+ -12345.6789 integerAndFractionParts
+ "
+!
+
rounded
"return the receiver rounded to the nearest integer"