Skip to content

Commit 8edd9b2

Browse files
committed
Allow convert nil to NaN in Numo::DFloat.cast
1 parent 1dd19df commit 8edd9b2

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/numo/narray/numo/types/float_macro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern double pow(double, double);
1212
#define m_zero 0.0
1313
#define m_one 1.0
1414

15-
#define m_num_to_data(x) NUM2DBL(x)
15+
#define m_num_to_data(x) (NIL_P(x) ? nan("") : NUM2DBL(x))
1616
#define m_data_to_num(x) rb_float_new(x)
1717

1818
#define m_from_double(x) (x)

test/narray_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,8 @@ class NArrayTest < Test::Unit::TestCase
644644
assert { $stderr.string == '' } # no warning message
645645
$stderr = STDERR
646646
end
647+
648+
test "Numo::DFloat.cast(Numo::RObject[1, nil, 3])" do
649+
assert { Numo::DFloat[1, Float::NAN, 3] == Numo::DFloat.cast(Numo::RObject[1, nil, 3]) }
650+
end
647651
end

0 commit comments

Comments
 (0)