Skip to content

Commit a205587

Browse files
authored
Merge pull request #207 from mrkn/allow_make_dfloat_with_nil
Allow convert nil to NaN when making Numo::DFloat
2 parents dc3d6bd + 44f4a86 commit a205587

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,9 @@ 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_equal(Numo::DFloat[1, Float::NAN, 3].format_to_a,
650+
Numo::DFloat.cast(Numo::RObject[1, nil, 3]).format_to_a)
651+
end
647652
end

0 commit comments

Comments
 (0)