wgsl: test hex float literal exact representation as f32
see test cases: https://dawn-review.googlesource.com/c/dawn/+/91429/comments/b5af104c_967ac87d
fn foo() {
let a = 0x8.0000ep+0f; // exactly represented
// Interesting case because f32(0x8.00001p+0) would round down to exactly representable
let b1 = 0x8.00001p+0f // not exactly representable. shader-creation error.
// Interesting case because f32(0x8.0000f8p+0) would round up to exactly representable
let b2 = 0x8.0000f8p+0f // not exactly representable. shader-creation error.
}
edited to fix comments
The f16 tests should also similar cases, with h suffix
fn foo() {
let h = 0x1p-200f;
}
was the test case from the other issue. Small magnitude which should fail as not representable.
Another thing that might happen is that a hex float might have more mantissa bits than is representable in an f64 (presumed AbstractFloat).
fn foo() {
// both these cases should be static error:
// need 54 bits mantissa.
// 1234123412341
let rounds_to_1_flat = 0x1.0000000000001p0; // rounds down to f64(1.0)
let rounds_above_1 = 0x1.0000000000008p0; // rounds up to f64(1.0) + f64 epsilon
}
Also, hex float values which are positive and negative infinity should be a shader error
Also, hex float values which are positive and negative infinity should be a shader error
Anything outside the finite range of the target type.
There are great explanations in this Tint code patch. https://dawn-review.googlesource.com/c/dawn/+/93100
It handles cases where a value maps to a subnormal f32 value. It also shows the f16 cases.
https://github.com/gpuweb/gpuweb/pull/3565 clarified the rule for hex floats: only 16 significant digits are required to be captured.
If the mantissa truncates to 16 significant digits, then the either teh truncated mantissa or truncated_mantissa_next can be used to get the mathematical value.
If the mantissa is 0 then 0 must be computed.
The test needs to check actual values parsed, not just pass/fail of parsing.
I updated the hex float parsing in SPIRV-Tools, and have crafted some good tests that demonstrate dropping extra significand bits. See https://github.com/KhronosGroup/SPIRV-Tools/pull/5025