Created
November 13, 2024 10:16
-
-
Save ufcpp/6af1e3e55d4821cb300c3aa2d42c086a to your computer and use it in GitHub Desktop.
(int)Math.Floor(float.MaxValue) の挙動違うらしい…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (int)Math.Floor(float.MaxValue) は、 | |
// .NET 8 だとなぜか int.MinValue | |
// .NET 9 だと int.MaxValue になってそう。 | |
// .NET 9 でだけ永久ループ… | |
M((int)Math.Floor(float.MaxValue), (int)Math.Floor(float.MaxValue)); | |
Console.WriteLine("done."); | |
static void M(int x, int y) | |
{ | |
// y が int.MaxValue だと、i++ がオーバーフローして永久ループになる。 | |
for (int i = x; i <= y; i++) ; | |
} |
https://learn.microsoft.com/ja-jp/dotnet/core/compatibility/jit/9.0/fp-to-integer
バグ修正ってわけではなく、「.NET 8 以前はそういう仕様」らしい…
浮動小数点数から整数への変換にAVX命令使いたいというのが目的の破壊的変更らしい。
runtime 97529
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
↓だけでも再現。
float → int の変換のバグかな。