I noticed that, like other languages, the only floating-point types built-in are f32 and f64. However, only having these can be limiting. I propose adding f128, and as mentioned in this thread f16 would likely be very useful for some workloads.
f128 would not be needed in most programs, but there are use cases for them, and it'd be nice to have it as a language built-in type. RISC-V is able to hardware accelerate them using the Q extension.
f16 is a more efficient type for workloads where you need tons of floats at low precision, like machine learning. Hardware using this is already widespread in Apple's neural engine and in mobile graphics.
Also, if covering IEEE-754 is desired, then there's also f256.
Original text:
Details
I noticed that, like other languages, the only floating-point types built-in are f32 and f64. However, I often have limitations with just these. I propose the following: fsize, freal, and f128
fsize would be like isize but for floats. Basically, use the version that's most efficient for your processor. On modern 64-bit processors with wide FPUs and/or 256-bit SIMD this would become f64.
Sometimes I want to be able to have a variable for real numbers, or I don't know what precision I want yet. In C++ I can do the following to have an abstract precision that I control via compiler flags:
#ifdef REAL_T_IS_DOUBLE
typedef double real_t;
#else
typedef float real_t;
#endif
I propose something similar in Rust, where you can just write freal or something and be able to change the precision later with compiler flags. The default would probably be f32.
Finally, it would be nice to have 128-bit floats (f128) in the language. These are not normally needed, but there are use cases for them, and it'd be nice to have it as a language built-in type. Some newer processors have 512-bit SIMD chipsets that can process these efficiently, though most don't.
If you only implement some of these proposals, that's fine too. Originally posted at rust-lang/rust#57928
I noticed that, like other languages, the only floating-point types built-in are
f32andf64. However, only having these can be limiting. I propose addingf128, and as mentioned in this threadf16would likely be very useful for some workloads.f128would not be needed in most programs, but there are use cases for them, and it'd be nice to have it as a language built-in type. RISC-V is able to hardware accelerate them using the Q extension.f16is a more efficient type for workloads where you need tons of floats at low precision, like machine learning. Hardware using this is already widespread in Apple's neural engine and in mobile graphics.Also, if covering IEEE-754 is desired, then there's also
f256.Original text:
Details
I noticed that, like other languages, the only floating-point types built-in are
f32andf64. However, I often have limitations with just these. I propose the following:, andfsize,frealf128fsizewould be likeisizebut for floats. Basically, use the version that's most efficient for your processor. On modern 64-bit processors with wide FPUs and/or 256-bit SIMD this would becomef64.Sometimes I want to be able to have a variable for real numbers, or I don't know what precision I want yet. In C++ I can do the following to have an abstract precision that I control via compiler flags:#ifdef REAL_T_IS_DOUBLEtypedef double real_t;#elsetypedef float real_t;#endifI propose something similar in Rust, where you can just writefrealor something and be able to change the precision later with compiler flags. The default would probably bef32.Finally, it would be nice to have 128-bit floats (
f128) in the language. These are not normally needed, but there are use cases for them, and it'd be nice to have it as a language built-in type. Some newer processors have 512-bit SIMD chipsets that can process these efficiently, though most don't.If you only implement some of these proposals, that's fine too. Originally posted at rust-lang/rust#57928