Skip to content

Commit af04c1d

Browse files
committed
Add handling of double values with just integer part
- Now at caller.
1 parent a7f5b0e commit af04c1d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/CLR/CorLib/corlib_native_System_Number.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
44
// See LICENSE file in the project root for full license information.
@@ -361,11 +361,22 @@ int Library_corlib_native_System_Number::Format_G(
361361
defaultPrecision = 9;
362362
break;
363363
case DATATYPE_R8:
364+
{
364365
// from .NET documentation:
365366
// When used with a Double value, the "G17" format specifier ensures that the original Double value
366367
// successfully round-trips.
367368
defaultPrecision = 17;
369+
370+
CLR_DOUBLE_TEMP_CAST number = (CLR_DOUBLE_TEMP_CAST)value->NumericByRef().r8;
371+
372+
// check if number is an integer
373+
if (number == (CLR_INT64_TEMP_CAST)number)
374+
{
375+
// this is an integer, set precision to a value achievable by the library
376+
defaultPrecision = 15;
377+
}
368378
break;
379+
}
369380
default:
370381
break;
371382
}

src/CLR/Helpers/nanoprintf/nanoprintf.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// Portions Copyright (c) 2006 - 2021 Skirrid Systems. All rights reserved.
44
// See LICENSE file in the project root for full license information.
@@ -93,7 +93,7 @@ Floating point
9393
#define DP_LIMIT 310
9494
#define MAX_POWER 256
9595
// [NF_CHANGE]
96-
#define FLOAT_DIGITS 18
96+
#define FLOAT_DIGITS 19
9797
// [END_NF_CHANGE]
9898
#else
9999
#define DP_LIMIT 40
@@ -271,6 +271,8 @@ static char *format_float(double number, flt_width_t ndigits, flt_width_t width,
271271
* to the answer in the fastest time, with the minimum number of
272272
* operations to introduce rounding errors.
273273
*/
274+
275+
// Normalise the number such that it lies in the range 1 <= n < 10.
274276
// First make small numbers bigger.
275277

276278
i = 0;

0 commit comments

Comments
 (0)