Skip to content

Commit b95ebfe

Browse files
committed
FIX/CHANGE: removed recently added NAN? native and replaced NUMBER? function with native equivalent which properly checks if decimal value is not a NAN
Previously: ``` >> number? 1.#NaN == true ``` Now it is `false` (which is logical as NaN means _Not a Number_) Although 1.#NaN is not a number, it is still of type DECIMAL! ``` >> type? 1.#NaN == decimal! ```
1 parent 89a055d commit b95ebfe

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/core/n-math.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -303,23 +303,33 @@ enum {SINE, COSINE, TANGENT};
303303
return R_RET;
304304
}
305305

306+
#endif //!USE_NO_INFINITY
307+
306308
/***********************************************************************
307309
**
308-
*/ REBNATIVE(nanq)
310+
*/ REBNATIVE(numberq)
309311
/*
310-
// nan?: native [
311-
// {Returns TRUE if the number is Not-a-Number.}
312-
// value [number!]
312+
// number?: native [
313+
// {Returns TRUE if the value is any type of number and not a NaN. }
314+
// value
313315
// ]
314316
***********************************************************************/
315317
{
316-
SET_LOGIC(D_RET, isnan(AS_DECIMAL(D_ARG(1))));
318+
BOOL result = FALSE;
319+
switch(VAL_TYPE(D_ARG(1))) {
320+
case REB_DECIMAL:
321+
if (!isnan(VAL_DECIMAL(D_ARG(1)))) result = TRUE;
322+
break;
323+
case REB_INTEGER:
324+
case REB_MONEY:
325+
case REB_PERCENT:
326+
result = TRUE;
327+
break;
328+
}
329+
SET_LOGIC(D_RET, result);
317330
return R_RET;
318331
}
319332

320-
#endif //!USE_NO_INFINITY
321-
322-
323333

324334
/***********************************************************************
325335
**

src/mezz/base-defs.r

+5-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ any-object?: func [
118118
value [any-type!]
119119
][find any-object! type? :value]
120120

121-
number?: func [
122-
"Return TRUE if value is a number (integer or decimal)."
123-
value [any-type!]
124-
][find number! type? :value]
121+
;@@ Oldes: replaced with native version - n-math.c (which handles NaN values too)
122+
;number?: func [
123+
; "Return TRUE if value is a number (integer or decimal)."
124+
; value [any-type!]
125+
;][find number! type? :value]
125126

126127
series?: func [
127128
"Return TRUE if value is any type of series."

0 commit comments

Comments
 (0)