mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: AsString(double) now empty for IsNull, autotest: Atof test fixed
This commit is contained in:
parent
039903de67
commit
e6d00d8697
4 changed files with 18 additions and 19 deletions
|
|
@ -2,24 +2,15 @@
|
|||
|
||||
using namespace Upp;
|
||||
|
||||
double Atoff(const char *s)
|
||||
{
|
||||
double result;
|
||||
return ScanDbl<char, byte>(result, s) ? result : -999;
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
SeedRandom(0);
|
||||
for(int i = 0; i < 100000; i++) {
|
||||
double x = (2 * Randomf() - 1) * pow(10, (int)Random(600) - 300);
|
||||
String s = AsString(x);
|
||||
double y = Atoff(s);
|
||||
// DDUMP(s);
|
||||
// DDUMP(atof(s));
|
||||
// DDUMP(y);
|
||||
ASSERT(abs((x - y) / x) < 0.00000000000001);
|
||||
String s = FormatG(x, 17);
|
||||
double y = Atof(s);
|
||||
ASSERT(x == y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\Atof.exe 22.06.2021 13:32:55, user: cxl
|
||||
* /home/cxl/out/autotest/CLANG.Debug.Debug_Full.Shared/Atof 31.08.2021 10:52:41, user: cxl
|
||||
|
||||
ScanDouble(".23") = 0.23
|
||||
ScanDouble("1.23") = 1.23
|
||||
|
|
@ -14,7 +14,7 @@ x = 2
|
|||
x = 3
|
||||
x = 1.23
|
||||
x = 12340000000
|
||||
x = -0.0000000001345
|
||||
x = -1.345e-10
|
||||
x = 0.23
|
||||
x = 1.23
|
||||
x = 0.23
|
||||
|
|
@ -24,7 +24,7 @@ x = 2
|
|||
x = 3
|
||||
x = 1.23
|
||||
x = 12340000000
|
||||
x = -0.0000000001345
|
||||
x = -1.345e-10
|
||||
x = 0.23
|
||||
x = 1.23
|
||||
x = 0.23
|
||||
|
|
@ -34,7 +34,7 @@ x = 2
|
|||
x = 3
|
||||
x = 1.23
|
||||
x = 12340000000
|
||||
x = -0.0000000001345
|
||||
x = -1.345e-10
|
||||
x = 0.23
|
||||
x = 1
|
||||
--------
|
||||
|
|
@ -48,14 +48,14 @@ p.ReadDouble() = 2
|
|||
p.ReadDouble() = 3
|
||||
p.ReadDouble() = 1.23
|
||||
p.ReadDouble() = 12340000000
|
||||
p.ReadDouble() = -0.0000000001345
|
||||
p.ReadDouble() = -1.345e-10
|
||||
--------
|
||||
p.ReadDouble() = 1
|
||||
p.ReadDouble() = 2
|
||||
p.ReadDouble() = 3
|
||||
p.ReadDouble() = 1.23
|
||||
p.ReadDouble() = 12340000000
|
||||
p.ReadDouble() = -0.0000000001345
|
||||
p.ReadDouble() = -1.345e-10
|
||||
p.ReadDouble() = 0.23
|
||||
p.ReadDouble() = 1
|
||||
--------
|
||||
|
|
|
|||
|
|
@ -412,6 +412,12 @@ String FormatDouble(double x)
|
|||
return String(h, FormatDouble(h, x));
|
||||
}
|
||||
|
||||
String FormatDoubleN(double x)
|
||||
{
|
||||
char h[512];
|
||||
return String(h, FormatDouble_(h, x, 15, FD_TOLERANCE(6)|FD_MINIMAL_EXP));
|
||||
}
|
||||
|
||||
char *FormatG(char *t, double x, int precision, dword flags)
|
||||
{
|
||||
return FormatDouble_(t, x, precision, flags);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ String FormatDouble(double x, int precision, dword flags = FD_TOLERANCE(6)|FD_MI
|
|||
char *FormatDouble(char *t, double x);
|
||||
String FormatDouble(double x);
|
||||
|
||||
String FormatDoubleN(double x);
|
||||
|
||||
String FormatDate(Date date, const char *format, int language = 0);
|
||||
String FormatTime(Time time, const char *format, int language = 0);
|
||||
|
||||
|
|
@ -68,7 +70,7 @@ template<> inline String AsString(const long& a) { return FormatInt64
|
|||
template<> inline String AsString(const unsigned long& a) { return FormatUInt64(a); }
|
||||
template<> inline String AsString(const int64& a) { return FormatInt64(a); }
|
||||
template<> inline String AsString(const uint64& a) { return FormatUInt64(a); }
|
||||
template<> inline String AsString(const double& a) { return FormatDouble(a); }
|
||||
template<> inline String AsString(const double& a) { return FormatDoubleN(a); }
|
||||
template<> inline String AsString(const float& a) { return FormatDouble(a); }
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue