mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update behavior-math-clamp-nan.md
Java now has Math.clamp and it also preserves NaN :-/
This commit is contained in:
parent
ab316b91d7
commit
1cf198706f
1 changed files with 1 additions and 1 deletions
|
@ -31,7 +31,7 @@ This can be a problem if:
|
||||||
As a consequence of this change, `math.clamp` return value `r` will always satisfy `a <= r <= b`.
|
As a consequence of this change, `math.clamp` return value `r` will always satisfy `a <= r <= b`.
|
||||||
Note that if the input or one of the limits is a negative zero we will not guarantee that the sign of the output is preserved when it's equal to zero; positive and negative zeros are considered equal under this proposal.
|
Note that if the input or one of the limits is a negative zero we will not guarantee that the sign of the output is preserved when it's equal to zero; positive and negative zeros are considered equal under this proposal.
|
||||||
|
|
||||||
The behavior of NaN clamping outside of Luau varies. Shading languages (HLSL in Direct3D, MSL in Metal) typically guarantee that `clamp(t, a, b)` is equal to a when t is NaN, although OpenGL and Vulkan leave result unspecified; C++ `std::clamp` provides no guarantees and in fact treats NaN as a technically-invalid input; C#, Rust and Julia preserve NaN; Zig returns the upper limit. Ruby raises an error when input is NaN. Swift does not implement clamping for floats. Despite the differences, we believe that for Luau domain and given that Luau only has a single number type, guaranteeing that the result is in the specified range is more valuable than preserving NaN, and returning the lower limit is more consistent with industry practice than returning upper limit.
|
The behavior of NaN clamping outside of Luau varies. Shading languages (HLSL in Direct3D, MSL in Metal) typically guarantee that `clamp(t, a, b)` is equal to a when t is NaN, although OpenGL and Vulkan leave result unspecified; C++ `std::clamp` provides no guarantees and in fact treats NaN as a technically-invalid input; C#, Rust, Java and Julia preserve NaN; Zig returns the upper limit. Ruby raises an error when input is NaN. Swift does not implement clamping for floats. Despite the differences, we believe that for Luau domain and given that Luau only has a single number type, guaranteeing that the result is in the specified range is more valuable than preserving NaN, and returning the lower limit is more consistent with industry practice than returning upper limit.
|
||||||
|
|
||||||
> The following text is non-normative as it relates to the specific implementation consequences.
|
> The following text is non-normative as it relates to the specific implementation consequences.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue