Skip to content

Commit

Permalink
Allow inputs of class single to jsonencode (bug #64949)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Rik committed Dec 2, 2023
1 parent 625d115 commit 3ba8df6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libinterp/corefcn/jsonencode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions test/json/jsonencode_BIST.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 3ba8df6

Please sign in to comment.