changeset 32523:dc06bb3bf1ed

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.
author Rik <rik@octave.org>
date Fri, 01 Dec 2023 16:37:40 -0800
parents 874ed29dcd2a
children d2eabc48cf80
files libinterp/corefcn/jsonencode.cc test/json/jsonencode_BIST.tst
diffstat 2 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/jsonencode.cc	Thu Nov 30 14:34:12 2023 -0800
+++ b/libinterp/corefcn/jsonencode.cc	Fri Dec 01 16:37:40 2023 -0800
@@ -75,7 +75,7 @@
   // 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");
--- a/test/json/jsonencode_BIST.tst	Thu Nov 30 14:34:12 2023 -0800
+++ b/test/json/jsonencode_BIST.tst	Fri Dec 01 16:37:40 2023 -0800
@@ -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'));