Display for f128

See title. Why f128 has not Display trait? Is it a error?

f128 is unstable anyway, so it might have been undecided yet what exactly to use as its Display implementation.

Almost every week I see something like this go by. I.e. all the support for these new floats is being added incrementally, not in a single shot.

(Click on the related label for a list of issues. I see offhand there's a f16 parsing and formatting issue for example.)

4 Likes

I'll admit to being somewhat surprised by the parsing issue.
I mean what's the difference between f16 and e.g. f32, other than precision and magnitude?

I don't have any information on that beyond what you'll get from reading the issue(s).

The difference lies with the fact that on most platforms f32 is supported by hardware thus you only need to execute an appropriate instruction and that's it, but for f16 or f128 you need support library which may or may not be available.

Yes, these new float types are pretty huge features so their support is coming in chunk by chunk. Would be quite a massive PR to add everything at once :slight_smile:

Our parsing and printing behavior and test-float-parse are really pretty specialized to f32 and f64, so there is work involved to make things more extensible. f16 will be pretty easy here and should come shortly after my test-float-parse rewrite.

f128 will take longer since code size becomes more of a concern: float parsing / printing is already pretty large, potentially much larger when soft integer ops need to be used (f128 has 112 bits of precision so it can't fit in a u64). So, we might want to do something like choose a slower but smaller implementation here. Decisions to be made once we are closer to that point.

For now there is a Debug ("{:?}") impl that can be used and just prints the hex, you can decode it to a decimal number with something like IEEE 754 Calculator (select binary16/binary128 at the bottom, paste the hex in the left box, hit enter).


These new types are still reasonably early in development. Please do feel free to experiment with them, but don't be too surprised if you run into wrong results due to ABI issues (f16 on x86), or can't build because of missing symbol linker errors (anything other than 64-bit linux with f128). rust/library/std/build.rs at d9284afea99e0969a0e692b9e9fd61ea4ba21366 · rust-lang/rust · GitHub should give a rough idea of platform support, most everything else is at Tracking Issue for `f16` and `f128` float types · Issue #116909 · rust-lang/rust · GitHub.

I'm going to try to mark these features incomplete just to make it clear that they aren't yet 100% ready for general testing.

6 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.