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

Might fix issue 58 #62

Merged
merged 3 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions TestcsFastFloat/Exaustive/ExaustiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ unsafe private void All32BitsValues()
{
for (uint w = 0; w <= 0xFFFFFFFF; w++)
{
float f;
uint word = (uint)(w);

Buffer.MemoryCopy(&word, &f, sizeof(float), sizeof(float));
float f = BitConverter.Int32BitsToSingle((int)word);

string sut = f.ToString().Replace(",", ".");

Expand Down
11 changes: 4 additions & 7 deletions csFastFloat/FastFloatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ public static float exact_power_of_ten(long power)
#endif
}

public static unsafe float ToFloat(bool negative, AdjustedMantissa am)
public static float ToFloat(bool negative, AdjustedMantissa am)
{
ulong word = am.mantissa;
word |= (ulong)(uint)(am.power2) << FloatBinaryConstants.mantissa_explicit_bits;
word = negative ? word | ((ulong)(1) << FloatBinaryConstants.sign_index) : word;

float d = 0;
Unsafe.Copy(ref d, &word);

return d;
uint truncated_word = (uint) word;
return BitConverter.Int32BitsToSingle((int)truncated_word);
}

public static float FastPath(ParsedNumberString pns)
Expand Down Expand Up @@ -572,4 +569,4 @@ unsafe static internal ParsedNumberString ParseNumberString(char* p, char* pend,



}
}