Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Dec 13, 2023
1 parent c715e94 commit e3e1f15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2394,8 +2394,8 @@ public static CBORObject FromByte(byte value) {
/// applications' purposes, and <c>Single.NaN</c> / <c>Float.NaN</c> is
/// only one of these equivalent forms. In fact,
/// <c>CBORObject.FromSingle(Single.NaN)</c> or
/// <c>CBORObject.FromSingle(Float.NaN)</c> could produce a CBOR-encoded
/// object that differs between DotNet and Java, because
/// <c>CBORObject.FromSingle(Float.NaN)</c> could produce a
/// CBOR-encoded object that differs between DotNet and Java, because
/// <c>Single.NaN</c> / <c>Float.NaN</c> may have a different form in
/// DotNet and Java (for example, the NaN value's sign may be negative
/// in DotNet, but positive in Java).</summary>
Expand Down
3 changes: 2 additions & 1 deletion CBOR/PeterO/Cbor/CBORUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,8 @@ public static int DoubleToHalfPrecisionIfSameValue(long bits) {
int newmant = unchecked((int)(mant >> 42));
return ((mant & ((1L << 42) - 1)) == 0) ? (sign | 0x7c00 | newmant) :
-1;
} else if (exp == 0 && mant == 0) { // positive or negative zero always fits in half precision
} else if (exp == 0 && mant == 0) { // positive or negative zero
always fits in half precision
return sign;
} else if (sexp >= 31) { // overflow
return -1;
Expand Down
36 changes: 19 additions & 17 deletions CBORTest/CBORNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public void TestCanTruncatedIntFitInUInt64() {

Assert.IsFalse(
CBORObject.FromInt32(-99).AsNumber().CanTruncatedIntFitInUInt64());
bool
b =
bool b =
CBORObject.FromEInteger(EInteger.FromInt32(1).ShiftLeft(65)).AsNumber()
.CanTruncatedIntFitInUInt64();
Assert.IsFalse(b);
Expand Down Expand Up @@ -717,42 +716,45 @@ public void TestEncodingZeros() {
TestCommon.CompareTestEqual(ToCN(0.0f), ToCN(-0.0f).Abs());

if (!CBORObject.FromDouble(0.0).AsNumber().CanFitInSingle()) {
Assert.Fail();
Assert.Fail();
}
if (!CBORObject.FromDouble(-0.0).AsNumber().CanFitInSingle()) {
Assert.Fail();
Assert.Fail();
}
if (!CBORObject.FromSingle(0.0f).AsNumber().CanFitInSingle()) {
Assert.Fail();
Assert.Fail();
}
if (!CBORObject.FromSingle(-0.0f).AsNumber().CanFitInSingle()) {
Assert.Fail();
Assert.Fail();
}

ToObjectTest.TestToFromObjectRoundTrip(0.0);
ToObjectTest.TestToFromObjectRoundTrip(0.0f);
ToObjectTest.TestToFromObjectRoundTrip(-0.0);
ToObjectTest.TestToFromObjectRoundTrip(-0.0f);

TestCommon.CompareTestEqual(ToCN(0.0), CBORObject.FromDouble(-0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0), CBORObject.FromDouble(0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(0.0f), CBORObject.FromSingle(-0.0f).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0f), CBORObject.FromSingle(0.0f).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(0.0),
CBORObject.FromDouble(-0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0),
CBORObject.FromDouble(0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(0.0f),
CBORObject.FromSingle(-0.0f).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0f),
CBORObject.FromSingle(0.0f).AsNumber().Negate());

byte[] bytes;
bytes=CBORObject.FromSingle(1.0f).EncodeToBytes();
bytes = CBORObject.FromSingle(1.0f).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
bytes=CBORObject.FromSingle(0.0f).EncodeToBytes();
bytes = CBORObject.FromSingle(0.0f).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
bytes=CBORObject.FromSingle(-0.0f).EncodeToBytes();
bytes = CBORObject.FromSingle(-0.0f).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
bytes=CBORObject.FromDouble(1.0).EncodeToBytes();
bytes = CBORObject.FromDouble(1.0).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
bytes=CBORObject.FromDouble(0.0).EncodeToBytes();
bytes = CBORObject.FromDouble(0.0).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
bytes=CBORObject.FromDouble(-0.0).EncodeToBytes();
bytes = CBORObject.FromDouble(-0.0).EncodeToBytes();
Assert.AreEqual(3, bytes.Length);
}

}
}

0 comments on commit e3e1f15

Please sign in to comment.