Skip to content

Commit b751885

Browse files
committed
FIX: 1.#NaN sorting inconsistency
resolves: Oldes/Rebol-issues#2493
1 parent 347d735 commit b751885

File tree

2 files changed

+15
-141
lines changed

2 files changed

+15
-141
lines changed

src/core/f-series.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@
234234
chkDecimal:
235235
if (Eq_Decimal(d1, d2))
236236
return 0;
237-
if (d1 < d2)
237+
if (d1 < d2
238+
#ifndef USE_NO_INFINITY
239+
|| isnan(d2)
240+
#endif
241+
)
238242
return -1;
239243
return 1;
240244

src/tests/units/series-test.r3

+10-140
Original file line numberDiff line numberDiff line change
@@ -280,60 +280,6 @@ Rebol [
280280
===end-group===
281281

282282

283-
===start-group=== "TRIM"
284-
--test-- "trim string!"
285-
str1: " a b c "
286-
str2: " ^(A0) ^-a b ^- c ^(2000) "
287-
mstr: { a ^-1^/ ab2^- ^/ ac3 ^/ ^/^/}
288-
--assert "a b c" = trim copy str1
289-
--assert "a b c" = trim/head/tail copy str1
290-
--assert "a b c " = trim/head copy str1
291-
--assert " a b c" = trim/tail copy str1
292-
; --assert "a b ^- c" = trim copy str2 ;- not like Red!
293-
--assert "a ^-1^/ab2^/ac3^/" = trim copy mstr
294-
--assert "a1ab2ac3" = trim/all { a ^-1^/ ab2^- ^/ ac3 ^/ ^/^/}
295-
--assert " ^-1^/ b2^- ^/ c3 ^/ ^/^/" = trim/with copy mstr #"a"
296-
--assert " ^-1^/ b2^- ^/ c3 ^/ ^/^/" = trim/with copy mstr 97
297-
--test-- "trim binary!"
298-
;@@ https://github.com/Oldes/Rebol-issues/issues/1482
299-
bin: #{0011001100}
300-
--assert #{110011} = trim copy bin
301-
--assert #{110011} = trim/head/tail copy bin
302-
--assert #{11001100} = trim/head copy bin
303-
--assert #{00110011} = trim/tail copy bin
304-
--assert #{1111} = trim/all copy bin
305-
--assert #{000000} = trim/all/with copy bin #{11}
306-
--assert #{} = trim #{0000}
307-
--assert #{} = trim/tail #{0000}
308-
--assert #{} = trim/head #{0000}
309-
--assert #{2061626320} = trim/head/tail to-binary " abc "
310-
--test-- "trim binary! incompatible"
311-
--assert all [error? e: try [trim/auto #{00}] e/id = 'bad-refines]
312-
--assert all [error? e: try [trim/lines #{00}] e/id = 'bad-refines]
313-
--assert all [error? e: try [trim/head/all #{00}] e/id = 'bad-refines]
314-
--assert all [error? e: try [trim/tail/all #{00}] e/id = 'bad-refines]
315-
--assert all [error? e: try [trim/tail/with #{00} 0] e/id = 'bad-refines]
316-
--assert all [error? e: try [trim/head/with #{00} 0] e/id = 'bad-refines]
317-
--test-- "trim binary! with index > 1"
318-
bin: #{0000110000}
319-
--assert #{00001100} = head trim/tail at copy bin 5
320-
--assert #{00110000} = head trim/head at copy bin 2
321-
--assert #{0011} = head trim/all at copy bin 2
322-
--test-- "trim block!"
323-
blk: [#[none] 1 #[none] 2 #[none]]
324-
;@@ https://github.com/Oldes/Rebol-issues/issues/825
325-
--assert [1 #[none] 2 #[none]] = trim/head copy blk
326-
--assert [#[none] 1 #[none] 2] = trim/tail copy blk
327-
;@@ https://github.com/Oldes/Rebol-issues/issues/2482
328-
--assert [1 #[none] 2] = trim copy blk
329-
--assert [1 2] = trim/all copy blk
330-
--assert all [error? e: try [trim/head/all []] e/id = 'bad-refines]
331-
--assert all [error? e: try [trim/tail/all []] e/id = 'bad-refines]
332-
333-
===end-group===
334-
335-
336-
337283
===start-group=== "REPLACE string!"
338284
;@@ https://github.com/Oldes/Rebol-issues/issues/54
339285
--test-- "issue-54"
@@ -866,18 +812,6 @@ Rebol [
866812
unset? pick b 2
867813
unset? b/2
868814
]
869-
--test-- "out of range"
870-
;@@ https://github.com/Oldes/Rebol-issues/issues/1057
871-
a: #{0102}
872-
--assert 3 = poke a 1 3
873-
--assert a = #{0302}
874-
--assert all [error? e: try [poke a 1 300] e/id = 'out-of-range]
875-
--assert 4 = a/1: 4
876-
--assert a = #{0402}
877-
--assert all [error? e: try [a/1: 400] e/id = 'out-of-range]
878-
--assert #{02} = change a 5
879-
--assert a = #{0502}
880-
--assert all [error? e: try [change a 500] e/id = 'out-of-range]
881815
===end-group===
882816

883817
===start-group=== "POKEZ"
@@ -969,22 +903,6 @@ Rebol [
969903
--assert 3 = length? x
970904
x: copy [] insert/dup x 5 -1
971905
--assert 0 = length? x
972-
--test-- "insert/part"
973-
;@@ https://github.com/Oldes/Rebol-issues/issues/856
974-
a: make block! 10
975-
b: at [1 2 3 4 5 6 7 8 9] 5
976-
--assert tail? insert/part a b 2
977-
--assert a = [5 6]
978-
insert/part clear a b 2147483647
979-
--assert a = [5 6 7 8 9]
980-
insert/part clear a b -2
981-
--assert a = [3 4]
982-
insert/part clear a b -2147483647
983-
--assert a = [1 2 3 4]
984-
--assert all [error? e: try [insert/part clear a b 2147483648] e/id = 'out-of-range]
985-
--assert all [error? e: try [insert/part clear a b -2147483649] e/id = 'out-of-range]
986-
987-
988906

989907
===end-group===
990908

@@ -1179,20 +1097,6 @@ Rebol [
11791097
--assert not past? b
11801098
===end-group===
11811099

1182-
===start-group=== "SNGLE?"
1183-
--test-- "single? block"
1184-
;@@ https://github.com/Oldes/Rebol-issues/issues/875
1185-
--assert single? [a]
1186-
--assert single? next [a b]
1187-
--assert not single? [a b]
1188-
--assert not single? []
1189-
--test-- "single? string!"
1190-
--assert single? "a"
1191-
--assert single? next "ab"
1192-
--assert not single? "ab"
1193-
--assert not single? ""
1194-
===end-group===
1195-
11961100

11971101
===start-group=== "SORT"
11981102

@@ -1268,6 +1172,16 @@ Rebol [
12681172
--assert ["fred" "Fred" "FRED"] == sort ["fred" "Fred" "FRED"]
12691173
--assert ["FRED" "Fred" "fred"] == sort/case ["Fred" "fred" "FRED"]
12701174

1175+
--test-- "SORT with NaN"
1176+
;@@ https://github.com/Oldes/Rebol-issues/issues/2493
1177+
; using `mold` in this test, because currently `(1.#NaN = 1.#NaN) == false` and so the test would fail!
1178+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#inf -1.0 1.#nan 1.0 -1.#inf 0 1.#NAN]
1179+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#inf -1.0 1.#nan 1.0 -1.#inf 1.#NAN 0]
1180+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#inf -1.0 1.#nan 1.0 1.#NAN -1.#inf 0]
1181+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#inf -1.0 1.#nan 1.#NAN 1.0 -1.#inf 0]
1182+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#inf 1.#NAN -1.0 1.#nan 1.0 -1.#inf 0]
1183+
--assert "[-1.#INF -1.0 0 1.0 1.#INF 1.#NaN 1.#NaN]" = mold sort [1.#NAN 1.#inf -1.0 1.#nan 1.0 -1.#inf 0]
1184+
12711185
===end-group===
12721186

12731187

@@ -1576,15 +1490,6 @@ Rebol [
15761490
;--assert txt = iconv #{FFFE50005901690068006C00E100730069007400} 'UTF16
15771491
--assert (next txt) = iconv next #{50F869686CE1736974} 28592
15781492

1579-
--test-- "ICONV from UTF-8"
1580-
;@@ https://github.com/Oldes/Rebol-issues/issues/2475
1581-
--assert "š" = iconv #{C5A1} 'utf8
1582-
--assert "š" = iconv #{C5A1} 'utf-8
1583-
--assert "š" = iconv #{C5A1} 'UTF8
1584-
--assert "š" = iconv #{C5A1} 'UTF-8
1585-
--assert "š" = iconv #{C5A1} 'CP65001
1586-
--assert "š" = iconv #{C5A1} 65001
1587-
15881493
--test-- "ICONV with empty imput"
15891494
--assert "" = iconv #{} 28592
15901495
--assert "" = iconv #{} 'utf8
@@ -1816,12 +1721,6 @@ Rebol [
18161721
--assert "<a<b b>>" = mold append <a> <b b>
18171722
--assert "<a<b b>>" = mold join <a> <b b>
18181723

1819-
--test-- "CRLF inside tag"
1820-
;@@ https://github.com/Oldes/Rebol-issues/issues/1233
1821-
; CRLF is not automatically converted inside tags
1822-
--assert #{410D0A} = to-binary first transcode #{3C410D0A3E}
1823-
--assert #{410A} = to-binary deline first transcode #{3C410D0A3E}
1824-
18251724
===end-group===
18261725

18271726

@@ -1898,13 +1797,6 @@ Rebol [
18981797
--assert block? random next [1 2]
18991798
--assert integer? random/only next [1 2]
19001799

1901-
--test-- "copy/part limit"
1902-
;@@ https://github.com/Oldes/Rebol-issues/issues/853
1903-
--assert [1] = copy/part tail [1] -2147483647
1904-
--assert [1] = copy/part tail [1] -2147483648
1905-
--assert all [error? e: try [copy/part tail [1] -2147483649] e/id = 'out-of-range]
1906-
1907-
19081800
===end-group===
19091801

19101802

@@ -2004,19 +1896,6 @@ Rebol [
20041896
;@@ https://github.com/Oldes/Rebol-issues/issues/690
20051897
--assert (split "This! is a. test? to see " charset "!?.") = ["This" " is a" " test" " to see "]
20061898

2007-
--test-- "split/at"
2008-
;@@ https://github.com/Oldes/Rebol-issues/issues/2490
2009-
--assert (split/at "a:b" #":") = ["a" "b"]
2010-
--assert (split/at "a:b:c" #":") = ["a" "b:c"]
2011-
--assert (split/at "a" #":") = ["a"]
2012-
--assert (split/at "a:" #":") = ["a" ""]
2013-
--assert (split/at ":b" #":") = ["" "b"]
2014-
--assert (split/at [1 a 2] 'a) = [[1] [2]]
2015-
--assert (split/at [1 a 2 3] 'a) = [[1] [2 3]]
2016-
--assert (split/at [1 a 2 a 3] 'a) = [[1] [2 a 3]]
2017-
--assert (split/at [1 2] 'a) = [[1 2]]
2018-
2019-
20201899
===end-group===
20211900

20221901

@@ -2184,8 +2063,6 @@ Rebol [
21842063
--assert [#[none] #[none]] = array 2
21852064
--test-- "array/initial"
21862065
--assert [0 0] = array/initial 2 0
2187-
;@@ https://github.com/Oldes/Rebol-issues/issues/360
2188-
--assert [["" ""] ["" ""]] = array/initial [2 2] ""
21892066
--test-- "array/initial func"
21902067
;@@ https://github.com/Oldes/Rebol-issues/issues/2193
21912068
--assert [10 9 8 7 6 5 4 3 2 1] = array/initial length: 10 func [] [-- length]
@@ -2258,13 +2135,6 @@ Rebol [
22582135

22592136
===end-group===
22602137

2261-
===start-group=== "MOVE"
2262-
--test-- "move/skip"
2263-
;@@ https://github.com/Oldes/Rebol-issues/issues/740
2264-
--assert all [error? e: try [move/skip [1 2 3] 2 0] e/id = 'out-of-range]
2265-
2266-
===end-group===
2267-
22682138
;-- VECTOR related tests moved to %vector-test.r3
22692139

22702140
~~~end-file~~~

0 commit comments

Comments
 (0)