■No92856 (ぬこ さん) に返信 一度に計算しないで分解して計算してみると わかると思いますが、 Dim hh2 = 4.0! / 2 Dim hh3 = 6.0! / 2 Dim fhh2 = Math.Floor(hh2) Dim fhh3 = Math.Floor(hh3) Dim chh2 = Math.Ceiling(hh2) Dim chh3 = Math.Ceiling(hh3) Dim ifhh2 = CInt(fhh2) Dim ifhh3 = CInt(fhh3) Dim ichh2 = CInt(chh2) Dim ichh3 = CInt(chh3) Console.WriteLine($"hh2 = {hh2}") Console.WriteLine($"hh3 = {hh3}") Console.WriteLine($"fhh2 = {fhh2}") Console.WriteLine($"fhh3 = {fhh3}") Console.WriteLine($"chh2 = {chh2}") Console.WriteLine($"chh3 = {chh3}") Console.WriteLine($"ifhh2 = {ifhh2}") Console.WriteLine($"ifhh3 = {ifhh3}") Console.WriteLine($"ichh2 = {ichh2}") Console.WriteLine($"ichh3 = {ichh3}") hh2 = 2 hh3 = 3 fhh2 = 2 fhh3 = 3 chh2 = 2 chh3 = 3 ifhh2 = 2 ifhh3 = 3 ichh2 = 2 ichh3 = 3 となります。 4.0! / 2 => 2 6.0! / 2 => 3 なので切り上げようが、切り捨てようが変わりません。 想像通り有効桁数内の計算となるので誤差は発生しないです。 特に2で割ることについては内部でもっている小数表現が 2進数を元にしているので誤差は出にくいかと思います。
- Child Tree -