Skip to content

Commit

Permalink
revert csharp NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
tianleiwu committed Sep 24, 2024
1 parent 718e05b commit 4664ddc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions csharp/src/Microsoft.ML.OnnxRuntime/OrtFloat16.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ internal static float CreateSingle(bool sign, byte exponent, uint significand)
/// <summary>
/// Float16 NaN
/// </summary>
public static Float16 NaN => new Float16(PositiveQNaNBits); // quiet NaN
public static Float16 NaN => new Float16(NegativeQNaNBits); // Same as System.Half.NaN

/// <summary>
/// Float16 Zero value
Expand Down Expand Up @@ -903,7 +903,7 @@ private static ushort RoundPackToFloat16(bool sign, short exp, ushort sig)
/// <summary>
/// BFloat16 NaN
/// </summary>
public static BFloat16 NaN => new BFloat16(PositiveQNaNBits); // quiet NaN
public static BFloat16 NaN => new BFloat16(NegativeQNaNBits); // .Net has no BFloat16. Follow Float16 style.

/// <summary>
/// BFloat16 Positive Zero
Expand Down
2 changes: 2 additions & 0 deletions include/onnxruntime/core/framework/float16.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class numeric_limits<onnxruntime::MLFloat16> {
}

static constexpr onnxruntime::MLFloat16 quiet_NaN() noexcept {
// The most significant fraction bit shall be 1, and no limitation on other fraction bits.
// Note that most frameworks use 0x7E00; while CUDA uses 0x7FFF; .Net System.Half.NaN uses 0xFE00;
return onnxruntime::MLFloat16::FromBits(0x7E00U); // Bits: sign(0), exponent(111,11), fraction(10,0000,0000)
}

Expand Down

0 comments on commit 4664ddc

Please sign in to comment.