Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix number conversion #816

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/CLR/CorLib/corlib_native_System_Number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ void nf_GetFormatString(char* formatStr, char formatCh, int precision, bool isLo
sprintf(formatStr, "%%%s%d%s%s", isFloat ? "." : isSigned ? "-0" : "0", precision, isLong ? "l" : isFloat ? "f" : "", formatCh == 'X' ? "X" : isFloat ? "" : isSigned ? "d" : "u");
}

void nf_RemoveTrailingZeros(char* buffer, int32_t length)
{
for(; length > 0; length--)
{
if( buffer[length] == '0' ||
buffer[length] < '0' ||
buffer[length] > '9')
{
// NULL every position that is not a digit or '0' (zero)
// this is OK because we are moving backwards and want to clear everything except the number representation
buffer[length] = 0;
}
else if(buffer[length] >= '0' || buffer[length] <= '9')
{
// stop on first char NOT a digit
// this is OK because we are moving backwards and want to stop on the first occurrence that is a digit other than 0
break;
}
}
}

HRESULT Library_corlib_native_System_Number::FormatNative___STATIC__STRING__OBJECT__CHAR__I4( CLR_RT_StackFrame& stack )
{
NATIVE_PROFILE_CLR_CORE();
Expand Down Expand Up @@ -143,7 +122,6 @@ HRESULT Library_corlib_native_System_Number::FormatNative___STATIC__STRING__OBJE
nf_GetFormatString(formatStr, formatCh, precision, false, true, false);

sprintf(result, formatStr, value->NumericByRef().r4);
nf_RemoveTrailingZeros(result, ARRAYSIZE(result));
#else
CLR_INT32 f = value->NumericByRef().r4;
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
Expand Down Expand Up @@ -175,7 +153,6 @@ HRESULT Library_corlib_native_System_Number::FormatNative___STATIC__STRING__OBJE
nf_GetFormatString(formatStr, formatCh, precision, false, true, false);

sprintf(result, formatStr, (CLR_DOUBLE_TEMP_CAST)value->NumericByRef().r8);
nf_RemoveTrailingZeros(result, ARRAYSIZE(result));
#else
CLR_INT64 d = (CLR_DOUBLE_TEMP_CAST)value->NumericByRef().r8;
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
Expand Down