[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #64949] jsonencode() not supporting single flo
|
From: |
Jesper PEdersen |
|
Subject: |
[Octave-bug-tracker] [bug #64949] jsonencode() not supporting single floats |
|
Date: |
Thu, 30 Nov 2023 04:46:40 -0500 (EST) |
URL:
<https://savannah.gnu.org/bugs/?64949>
Summary: jsonencode() not supporting single floats
Group: GNU Octave
Submitter: jesper_p
Submitted: Thu 30 Nov 2023 09:46:37 AM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Unexpected Error or Warning
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: 8.4.0
Discussion Lock: Any
Operating System: Any
Fixed Release: None
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Thu 30 Nov 2023 09:46:37 AM UTC By: Jesper PEdersen <jesper_p>
Passing single-floats to jsonencode() throws an error (it works in Matlab).
E.g.:
octave:1> jsonencode(single(123.456))
error: jsonencode: unsupported type
I've mostly been a user of Octave rather than a contributor so bear with me.
However, I looked into the code and found that I could fix the issue by a
simple modification to jsonencode.cc
diff -r f511a54000f7 libinterp/corefcn/jsonencode.cc
--- a/libinterp/corefcn/jsonencode.cc Tue Nov 28 22:02:57 2023 -0800
+++ b/libinterp/corefcn/jsonencode.cc Thu Nov 30 10:41:25 2023 +0100
@@ -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.is_double_type () || obj.is_single_type ())
writer.Double (value);
else
error ("jsonencode: unsupported type");
I am aware that the underlying RapidJSON only supports double which means that
I get some conversion artifacts like below. However, I feel that most users
would prefer this simple solution over the current limitation. Or maybe
someone has an idea of how to avoid below artifacts?
Behaviour after testing the above fix:
octave:1> jsonencode(single(123.456))
ans = 123.45600128173828
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?64949>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
| [Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Octave-bug-tracker] [bug #64949] jsonencode() not supporting single floats,
Jesper PEdersen <=