From 3ba8df655d949cbc9eb75a0f04635c6a4a83e5d7 Mon Sep 17 00:00:00 2001 From: Rik Date: Fri, 1 Dec 2023 16:37:40 -0800 Subject: [PATCH] Allow inputs of class single to jsonencode (bug #64949) * jsonencode.cc (encode_numeric): Change input validation test to isfloat() rather than is_double_type() to also accept single inputs. * jsonencode_BIST.tst: Add commented test for bug #64960. --- libinterp/corefcn/jsonencode.cc | 2 +- test/json/jsonencode_BIST.tst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libinterp/corefcn/jsonencode.cc b/libinterp/corefcn/jsonencode.cc index ff6523fbe7..5753465f65 100644 --- a/libinterp/corefcn/jsonencode.cc +++ b/libinterp/corefcn/jsonencode.cc @@ -75,7 +75,7 @@ encode_numeric (T& writer, const octave_value& obj, // Possibly write NULL for non-finite values (-Inf, Inf, NaN, NA) else if (ConvertInfAndNaN && ! octave::math::isfinite (value)) writer.Null (); - else if (obj.is_double_type ()) + else if (obj.isfloat ()) writer.Double (value); else error ("jsonencode: unsupported type"); diff --git a/test/json/jsonencode_BIST.tst b/test/json/jsonencode_BIST.tst index a39e5ce91e..37f8f9c213 100644 --- a/test/json/jsonencode_BIST.tst +++ b/test/json/jsonencode_BIST.tst @@ -15,6 +15,8 @@ %! assert (isequal (jsonencode (logical (1)), 'true')); %! assert (isequal (jsonencode (logical (0)), 'false')); %! assert (isequal (jsonencode (50.025), '50.025')); +%% FIXME: Uncomment when bug #64960 is fixed +%!# assert (isequal (jsonencode (single (50.025)), '50.025')); %! assert (isequal (jsonencode (NaN), 'null')); %! assert (isequal (jsonencode (NA), 'null')); % Octave-only test %! assert (isequal (jsonencode (Inf), 'null'));