From 1a42e39d5429e5a0bacbe88ca571fff251e0db3f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 14:39:04 +0000 Subject: [PATCH 01/10] Fix Format_F to handle ToString("F0") for doubles and floats Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 34a9939a03..de7871dfc0 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -752,7 +752,11 @@ int Library_corlib_native_System_Number::Format_F( } buffer[ret] = 0; } + } + // apply negative sign and decimal separator replacements for all types + if (ret > 0) + { ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } From 2223b094ba0c9d72a53710adeb5757acf62db83d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 14:40:23 +0000 Subject: [PATCH 02/10] Improve comment clarity per code review feedback Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index de7871dfc0..98a6110526 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -754,7 +754,7 @@ int Library_corlib_native_System_Number::Format_F( } } - // apply negative sign and decimal separator replacements for all types + // apply negative sign and decimal separator replacements for all data types when formatting is successful if (ret > 0) { ret = ReplaceNegativeSign(buffer, ret, negativeSign); From 2d95348c993530ac05f9e52ab395e453c95c8423 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:29:45 +0000 Subject: [PATCH 03/10] Fix Format_F to handle negative zero and apply culture replacements to floats Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 98a6110526..aff14678d0 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -754,9 +754,18 @@ int Library_corlib_native_System_Number::Format_F( } } - // apply negative sign and decimal separator replacements for all data types when formatting is successful + // apply culture-specific replacements for all types when formatting is successful if (ret > 0) { + // for floating-point types, handle negative zero + if (!isIntegerDataType && ret == 2 && buffer[0] == '-' && buffer[1] == '0') + { + // convert "-0" to "0" + buffer[0] = '0'; + buffer[1] = 0; + ret = 1; + } + ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } From 29ec4d5206de0ccc1ae7859e648a5e30f58fa1ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:43:21 +0000 Subject: [PATCH 04/10] Fix Format_F to handle integer value 0 with precision 0 Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index aff14678d0..786496f5d9 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -753,6 +753,14 @@ int Library_corlib_native_System_Number::Format_F( buffer[ret] = 0; } } + else if (isIntegerDataType && ret == 0) + { + // special case: when precision is 0 and value is 0, snprintf returns empty string + // we need to output "0" instead + buffer[0] = '0'; + buffer[1] = 0; + ret = 1; + } // apply culture-specific replacements for all types when formatting is successful if (ret > 0) From 86d5ea7d71cf775d69c9d9b7c15854f45efb9b3d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 16:27:01 +0000 Subject: [PATCH 05/10] Remove negative zero handling to debug test failure Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 786496f5d9..50b86aee84 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -765,15 +765,6 @@ int Library_corlib_native_System_Number::Format_F( // apply culture-specific replacements for all types when formatting is successful if (ret > 0) { - // for floating-point types, handle negative zero - if (!isIntegerDataType && ret == 2 && buffer[0] == '-' && buffer[1] == '0') - { - // convert "-0" to "0" - buffer[0] = '0'; - buffer[1] = 0; - ret = 1; - } - ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } From 3b78ed83600c3025e4aeacc572fc4b39dad55194 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 16:59:47 +0000 Subject: [PATCH 06/10] Apply culture replacements to floating-point types in Format_F Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 50b86aee84..40c90779e1 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -752,18 +752,12 @@ int Library_corlib_native_System_Number::Format_F( } buffer[ret] = 0; } - } - else if (isIntegerDataType && ret == 0) - { - // special case: when precision is 0 and value is 0, snprintf returns empty string - // we need to output "0" instead - buffer[0] = '0'; - buffer[1] = 0; - ret = 1; - } - // apply culture-specific replacements for all types when formatting is successful - if (ret > 0) + ret = ReplaceNegativeSign(buffer, ret, negativeSign); + ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); + } + // apply culture-specific replacements for floating-point types + else if (!isIntegerDataType && ret > 0) { ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); From 6e3c734f6ec153e4ec614ff0aeabeb43e5e5e48b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 17:50:32 +0000 Subject: [PATCH 07/10] Comprehensive fix for Format_F: handle integer 0, float culture, and negative zero Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- src/CLR/CorLib/corlib_native_System_Number.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 40c90779e1..4b49f1b13e 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -756,9 +756,25 @@ int Library_corlib_native_System_Number::Format_F( ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } + else if (isIntegerDataType && ret == 0) + { + // special case: when precision is 0 and value is 0, snprintf returns empty string + // we need to output "0" instead + buffer[0] = '0'; + buffer[1] = 0; + ret = 1; + } // apply culture-specific replacements for floating-point types else if (!isIntegerDataType && ret > 0) { + // handle negative zero: -0.0 should be formatted as "0" + if (precision == 0 && ret >= 2 && buffer[0] == '-' && buffer[1] == '0') + { + // remove the negative sign for "-0" + memmove(buffer, &buffer[1], ret); + ret--; + } + ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } From dea43e9a6c5318e773aaa2c66043f2993851ce74 Mon Sep 17 00:00:00 2001 From: "nfbot[bot]" Date: Thu, 30 Oct 2025 18:30:14 +0000 Subject: [PATCH 08/10] Code style fixes for nanoframework/nf-interpreter PR#3228 (#3229) --- src/CLR/CorLib/corlib_native_System_Number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 4b49f1b13e..35954b505c 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -774,7 +774,7 @@ int Library_corlib_native_System_Number::Format_F( memmove(buffer, &buffer[1], ret); ret--; } - + ret = ReplaceNegativeSign(buffer, ret, negativeSign); ret = ReplaceDecimalSeparator(buffer, ret, decimalSeparator); } From d492af668c759f5649eca33238b5720e91110f65 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 00:35:04 +0000 Subject: [PATCH 09/10] Fix negative zero handling by checking actual value, not string Co-authored-by: josesimoes <1881520+josesimoes@users.noreply.github.com> --- .../CorLib/corlib_native_System_Number.cpp | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index 35954b505c..a6d82fdba5 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -705,6 +705,28 @@ int Library_corlib_native_System_Number::Format_F( bool isIntegerDataType = IsIntegerDataType(dataType); + // For floating-point types with precision 0, check if we have negative zero case + // This happens when a small negative value (e.g., -0.099) rounds to 0 + bool isNegativeZeroCase = false; + if (!isIntegerDataType && precision == 0) + { + double val = 0.0; + if (dataType == DATATYPE_R4) + { + val = (double)value->NumericByRef().r4; + } + else if (dataType == DATATYPE_R8) + { + val = (double)value->NumericByRef().r8; + } + + // Check if value is negative and would round to 0 with precision 0 + if (val < 0.0 && val > -0.5) + { + isNegativeZeroCase = true; + } + } + char formatStr[FORMAT_FMTSTR_BUFFER_SIZE]; snprintf( formatStr, @@ -767,10 +789,10 @@ int Library_corlib_native_System_Number::Format_F( // apply culture-specific replacements for floating-point types else if (!isIntegerDataType && ret > 0) { - // handle negative zero: -0.0 should be formatted as "0" - if (precision == 0 && ret >= 2 && buffer[0] == '-' && buffer[1] == '0') + // handle negative zero: if the value was negative but rounds to 0, remove the minus sign + if (isNegativeZeroCase && buffer[0] == '-') { - // remove the negative sign for "-0" + // remove the negative sign memmove(buffer, &buffer[1], ret); ret--; } From 2737af9f827ef8e84aaaba0269675da89c7127e6 Mon Sep 17 00:00:00 2001 From: "nfbot[bot]" Date: Fri, 31 Oct 2025 00:54:28 +0000 Subject: [PATCH 10/10] Code style fixes for nanoframework/nf-interpreter PR#3228 (#3230) --- src/CLR/CorLib/corlib_native_System_Number.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index a6d82fdba5..f1c048d5a3 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -719,7 +719,7 @@ int Library_corlib_native_System_Number::Format_F( { val = (double)value->NumericByRef().r8; } - + // Check if value is negative and would round to 0 with precision 0 if (val < 0.0 && val > -0.5) {