--- lang: ja-jp breaks: true --- # C# `NaN`文字列が `double.TryParse` で `System.Double.NaN` にパースされる。`float`も同様。 2021-05-27 知らなかった。。。 :::info C言語でも `0.0 / 0.0` の結果は `nan` となる。 ::: ## 検証コード ```csharp= static void Main(string[] args) { double zero = 0; System.Double dbl = 1.0 / zero; Console.WriteLine(dbl); //System.Double.NaN; //System.Double.PositiveInfinity; //System.Double.NegativeInfinity; double val2 = 0; if (Double.TryParse("NaN", out val2)) { Console.WriteLine(val2); } decimal dec2 = 0; if (decimal.TryParse("NaN", out dec2)) { Console.WriteLine(dec2); } decimal dZero = 0; decimal decVal = 0 / dZero; Console.WriteLine("dbl"); } ``` ###### tags: `C#` `NaN` `double.TryParse`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up