Repository navigation
|
I see from the WebGpu WGSL document that NaN may not even be supported on some platforms. However, in many applications eg GIS and Statistics there can be NO_DATA values which would be a good candidate to be represented by NaN. In my tests on a Mac M1 the following returns false for a NaN value, but my understanding is that NaN is the only number that is not equal to itself. fn isNaN(v:f32) -> bool { expected: true Could support for NaN and also a library function isNaN be included in the WebGPU + WGSL standards? |
Replies: 2 comments
|
I added NaN support But it will not work everywhere as you said. First statement pass isNaN() test for me, but next four statements is not. So as you see result inconsistent between expressions, graphics APIs and machines. Not looks like a standard. P.S. Closest idea discussed here #2076 where was suggested |
|
NaN support cannot be added to the core language because it requires hardware support. Most GPU architectures save on their hardware transistor budget by having their float ALUs ignore the possibility of NaN and Infinities, so even when you can construct a NaN (as in @munrocket's answer), it will result in undefined behavior instead of the IEEE754 behavior. It may be possible to add as an optional feature in the future, but reach would be limited. I recommend that you find other values for your NO_DATA values, such as the min/max f32 values ( |
NaN support cannot be added to the core language because it requires hardware support. Most GPU architectures save on their hardware transistor budget by having their float ALUs ignore the possibility of NaN and Infinities, so even when you can construct a NaN (as in @munrocket's answer), it will result in undefined behavior instead of the IEEE754 behavior.
It may be possible to add as an optional feature in the future, but reach would be limited. I recommend that you find other values for your NO_DATA values, such as the min/max f32 values (
-0xffffffp104and0xffffffp104in hex float form, i.e. 0xffffff × 2104, alternatively written0x1.fffff8p127). #3431 tracks the addition of those con…