# HG changeset patch # User Rik # Date 1701477460 28800 # Node ID dc06bb3bf1ed12f3419a89afdc8299607b1810bd # Parent 874ed29dcd2a87617b813bb8be6326c59ee14545 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. diff -r 874ed29dcd2a -r dc06bb3bf1ed libinterp/corefcn/jsonencode.cc --- 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"); diff -r 874ed29dcd2a -r dc06bb3bf1ed test/json/jsonencode_BIST.tst --- 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'));