Search code examples
floating-pointcrystal-lang

How to parse an 80-bit floating point number in Crystal?


I want to read an 80-bit floating point number (according to the IEEE 754 standard) from an IO object and store it in a usable type like BigDecimal, Float64 or something similar. (After reading the number, I don't need to keep the full precision. That's why I'm also fine with a Float64.)

Right now, I'm calculating the number myself. Is there any built-in way of doing this with Crystal's standard library?

Thanks.


Solution

  • Crystal's standard library has no built-in support for reading 80bit or arbitrary width binary representations of floating point numbers. Only the languages's primitive types (Float32 and Float64) are supported out of the box (see IO::ByteFormat).