@@ -387,6 +387,57 @@ public static long fromFixedPoint(final int mantissa, final int numberOfDigits)
387
387
* The only difference from {@link #fromDouble(double)} is that it fudges the last digit of
388
388
* mantissa towards decimal 0 as long as the result produces shorter mantissa and
389
389
* is still within rounding error range.
390
+ * It tries to guarantee correct decimal->double->decimal roundtrip.
391
+ * I.e. the doubleValue(fromDouble(value)) and doubleValue(fromDecimalDouble(value)) must
392
+ * produce equal values. This mean the correction must be within +-Math.ulp(value) interval.
393
+ * These are examples of the fromDouble, fromDecimalDouble and sprintf('%.30f') from Octave
394
+ * ---------------------------------------------------
395
+ * Double: 0.898317491899492
396
+ * fromDouble: 0.8983174918994919
397
+ * fromDecimalDouble: 0.898317491899492
398
+ * sprintf('%.30f') 0.898317491899491948892375603464
399
+ * ---------------------------------------------------
400
+ * Double: 0.954510556332067
401
+ * fromDouble: 0.9545105563320671
402
+ * fromDecimalDouble: 0.954510556332067
403
+ * sprintf('%.30f') 0.954510556332067050533396468381
404
+ * ---------------------------------------------------
405
+ * Double: 0.531006278913499
406
+ * fromDouble: 0.5310062789134991
407
+ * fromDecimalDouble: 0.531006278913499
408
+ * sprintf('%.30f') 0.531006278913499052407587441849
409
+ * ---------------------------------------------------
410
+ * Also, let's consider the examples when fromDouble and fromDecimalDouble produce exactly the save
411
+ * result:
412
+ * ---------------------------------------------------
413
+ * Double: 720491.5510000001
414
+ * fromDouble: 720491.5510000001
415
+ * fromDecimalDouble: 720491.5510000001
416
+ * sprintf('%.30f') 720491.551000000094063580036163330078
417
+ * ---------------------------------------------------
418
+ * Double: 74.51231011000002
419
+ * fromDouble: 74.51231011000002
420
+ * fromDecimalDouble: 74.51231011000002
421
+ * sprintf('%.30f') 74.512310110000015583864296786487
422
+ * ---------------------------------------------------
423
+ * Double: 9.889899999999999
424
+ * fromDouble: 9.889899999999999
425
+ * fromDecimalDouble: 9.889899999999999
426
+ * sprintf('%.30f') 9.889899999999999025135366537143
427
+ * ---------------------------------------------------
428
+ * Note! There are also cases when both fromDouble and fromDecimalDouble produce rounded value because decimal64
429
+ * can save only 16 digits from mantissa:
430
+ * ---------------------------------------------------
431
+ * Double: 25087.309999999998
432
+ * fromDouble: 25087.31
433
+ * fromDecimalDouble: 25087.31
434
+ * sprintf('%.30f') 25087.309999999997671693563461303711
435
+ * ---------------------------------------------------
436
+ * Double: 320000.00000000006
437
+ * fromDouble: 320000.0000000001
438
+ * fromDecimalDouble: 320000.0000000001
439
+ * sprintf('%.30f') 320000.000000000058207660913467407227
440
+ * ---------------------------------------------------
390
441
*
391
442
* @param value source 64-bit binary floating point value
392
443
* @return New {@code DFP} value.
0 commit comments