Double floats doesn't work correctly #3

Closed
opened 2017-05-31 10:17:24 +00:00 by erikronstrom · 1 comment
erikronstrom commented 2017-05-31 10:17:24 +00:00 (Migrated from github.com)

encode-data checks for float (using typecase), and encodes it using encode-float32. However, if a double float is passed to encode-data, it will also match the float clause and will be encoded as a single-float.

Depending on the implementation, this may give the correct result, throw an error, or silently fail with the wrong result. (That's what happened to me)

A simple fix would be to change the typecond clause in encode-data (and encode-typetags) from float to single-float. This could later be complemented by a check for double-float, calling encode-float64.

Another possible simple fix would be to coerce the value to a single-float before passing it to encode-float32.

`encode-data` checks for `float` (using `typecase`), and encodes it using `encode-float32`. However, if a double float is passed to `encode-data`, it will also match the `float` clause and will be encoded as a `single-float`. Depending on the implementation, this may give the correct result, throw an error, or silently fail with the wrong result. (That's what happened to me) A simple fix would be to change the `typecond` clause in `encode-data` (and `encode-typetags`) from `float` to `single-float`. This could later be complemented by a check for `double-float`, calling `encode-float64`. Another possible simple fix would be to coerce the value to a single-float before passing it to `encode-float32`.
zzkt commented 2024-01-02 08:23:08 +00:00 (Migrated from github.com)

float encoding for single-float and double-float should work as expected now. 2bad195

float encoding for `single-float` and `double-float` should work as expected now. 2bad195
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: zzkt/osc#3
No description provided.