Skip to content

Commit 9743af8

Browse files
committed
update Java version
1 parent 402d459 commit 9743af8

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

api/com.upokecenter.cbor.CBORObject.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,17 @@ Generates a CBOR object from a byte (0 to 255).
23722372

23732373
### FromObject
23742374
public static CBORObject FromObject​(float value)
2375-
Generates a CBOR object from a 32-bit floating-point number.
2375+
Generates a CBOR object from a 32-bit floating-point number. The input value
2376+
can be a not-a-number (NaN) value (such as <code>Float.NaN</code> in
2377+
DotNet or Float.NaN in Java); however, NaN values have multiple
2378+
forms that are equivalent for many applications' purposes, and
2379+
<code>Float.NaN</code> / <code>Float.NaN</code> is only one of these equivalent
2380+
forms. In fact, <code>CBORObject.FromObject(Float.NaN)</code> or
2381+
<code>CBORObject.FromObject(Float.NaN)</code> could produce a CBOR-encoded
2382+
object that differs between DotNet and Java, because
2383+
<code>Float.NaN</code> / <code>Float.NaN</code> may have a different form in
2384+
DotNet and Java (for example, the NaN value's sign may be negative
2385+
in DotNet, but positive in Java).
23762386

23772387
**Parameters:**
23782388

@@ -2384,7 +2394,15 @@ Generates a CBOR object from a 32-bit floating-point number.
23842394

23852395
### FromObject
23862396
public static CBORObject FromObject​(double value)
2387-
Generates a CBOR object from a 64-bit floating-point number.
2397+
Generates a CBOR object from a 64-bit floating-point number. The input value
2398+
can be a not-a-number (NaN) value (such as <code>Double.NaN</code>);
2399+
however, NaN values have multiple forms that are equivalent for many
2400+
applications' purposes, and <code>Double.NaN</code> is only one of these
2401+
equivalent forms. In fact, <code>CBORObject.FromObject(Double.NaN)</code>
2402+
could produce a CBOR-encoded object that differs between DotNet and
2403+
Java, because <code>Double.NaN</code> may have a different form in DotNet
2404+
and Java (for example, the NaN value's sign may be negative in
2405+
DotNet, but positive in Java).
23882406

23892407
**Parameters:**
23902408

src/main/java/com/upokecenter/cbor/CBORObject.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,17 @@ public static CBORObject FromObject(byte value) {
22622262
}
22632263

22642264
/**
2265-
* Generates a CBOR object from a 32-bit floating-point number.
2265+
* Generates a CBOR object from a 32-bit floating-point number. The input value
2266+
* can be a not-a-number (NaN) value (such as <code>Float.NaN</code> in
2267+
* DotNet or Float.NaN in Java); however, NaN values have multiple
2268+
* forms that are equivalent for many applications' purposes, and
2269+
* <code>Float.NaN</code> / <code>Float.NaN</code> is only one of these equivalent
2270+
* forms. In fact, <code>CBORObject.FromObject(Float.NaN)</code> or
2271+
* <code>CBORObject.FromObject(Float.NaN)</code> could produce a CBOR-encoded
2272+
* object that differs between DotNet and Java, because
2273+
* <code>Float.NaN</code> / <code>Float.NaN</code> may have a different form in
2274+
* DotNet and Java (for example, the NaN value's sign may be negative
2275+
* in DotNet, but positive in Java).
22662276
* @param value The parameter {@code value} is a 32-bit floating-point number.
22672277
* @return A CBOR object generated from the given number.
22682278
*/
@@ -2273,7 +2283,15 @@ public static CBORObject FromObject(float value) {
22732283
}
22742284

22752285
/**
2276-
* Generates a CBOR object from a 64-bit floating-point number.
2286+
* Generates a CBOR object from a 64-bit floating-point number. The input value
2287+
* can be a not-a-number (NaN) value (such as <code>Double.NaN</code>);
2288+
* however, NaN values have multiple forms that are equivalent for many
2289+
* applications' purposes, and <code>Double.NaN</code> is only one of these
2290+
* equivalent forms. In fact, <code>CBORObject.FromObject(Double.NaN)</code>
2291+
* could produce a CBOR-encoded object that differs between DotNet and
2292+
* Java, because <code>Double.NaN</code> may have a different form in DotNet
2293+
* and Java (for example, the NaN value's sign may be negative in
2294+
* DotNet, but positive in Java).
22772295
* @param value The parameter {@code value} is a 64-bit floating-point number.
22782296
* @return A CBOR object generated from the given number.
22792297
*/

src/test/java/com/upokecenter/test/CBORNumberTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,6 @@ public void TestAsEDecimal() {
643643
.AsNumber().ToEDecimal();
644644
Assert.assertEquals(objectTemp, objectTemp2);
645645
}
646-
{
647-
String stringTemp = ToObjectTest.TestToFromObjectRoundTrip(
648-
Float.NaN).AsNumber().ToEDecimal().toString();
649-
Assert.assertEquals(
650-
"NaN",
651-
stringTemp);
652-
}
653646
{
654647
Object objectTemp = CBORTestCommon.DecPosInf;
655648
Object objectTemp2 =
@@ -665,12 +658,19 @@ public void TestAsEDecimal() {
665658
Assert.assertEquals(objectTemp, objectTemp2);
666659
}
667660
{
668-
Object objectTemp = "NaN";
669-
Object objectTemp2 =
661+
boolean bo = ToObjectTest.TestToFromObjectRoundTrip(
662+
Double.NaN).AsNumber().ToEDecimal().IsNaN();
663+
if (!(bo)) {
664+
Assert.fail();
665+
}
666+
}
667+
{
668+
boolean bo =
670669
ToObjectTest.TestToFromObjectRoundTrip(
671-
Double.NaN).AsNumber().ToEDecimal()
672-
.toString();
673-
Assert.assertEquals(objectTemp, objectTemp2);
670+
Float.NaN).AsNumber().ToEDecimal().IsNaN();
671+
if (!(bo)) {
672+
Assert.fail();
673+
}
674674
}
675675
try {
676676
CBORObject.NewArray().AsNumber().ToEDecimal();

src/test/java/com/upokecenter/test/CBORObjectTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9613,7 +9613,7 @@ public static void TestParseNumberFxxLine(String line) {
96139613
Assert.fail(line);
96149614
}
96159615
String f64 = line.substring(4 + 1 + 8 + 1, (4 + 1 + 8 + 1)+(16));
9616-
if (line.charAt(4+ 1 + 25) != ' ') {
9616+
if (line.charAt(4 + 26) != ' ') {
96179617
Assert.fail(line);
96189618
}
96199619
String str = line.substring(4 + 1 + 8 + 1 + 16 + 1);

src/test/java/com/upokecenter/test/ToObjectTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,6 @@ public void TestAsEDecimal() {
477477
.ToObject(EDecimal.class);
478478
Assert.assertEquals(objectTemp, objectTemp2);
479479
}
480-
{
481-
String stringTemp = ToObjectTest.TestToFromObjectRoundTrip(Float.NaN)
482-
.ToObject(EDecimal.class).toString();
483-
Assert.assertEquals(
484-
"NaN",
485-
stringTemp);
486-
}
487480
{
488481
Object objectTemp = CBORTestCommon.DecPosInf;
489482
Object objectTemp2 =
@@ -499,11 +492,18 @@ public void TestAsEDecimal() {
499492
Assert.assertEquals(objectTemp, objectTemp2);
500493
}
501494
{
502-
Object objectTemp = "NaN";
503-
Object objectTemp2 =
504-
ToObjectTest.TestToFromObjectRoundTrip(Double.NaN)
505-
.ToObject(EDecimal.class).toString();
506-
Assert.assertEquals(objectTemp, objectTemp2);
495+
boolean bo = ((EDecimal)ToObjectTest.TestToFromObjectRoundTrip(Float.NaN)
496+
.ToObject(EDecimal.class)).IsNaN();
497+
if (!(bo)) {
498+
Assert.fail();
499+
}
500+
}
501+
{
502+
boolean bo = ((EDecimal)ToObjectTest.TestToFromObjectRoundTrip(Double.NaN)
503+
.ToObject(EDecimal.class)).IsNaN();
504+
if (!(bo)) {
505+
Assert.fail();
506+
}
507507
}
508508
try {
509509
CBORObject.NewArray().ToObject(EDecimal.class);

0 commit comments

Comments
 (0)