зеркало из https://github.com/mozilla/pjs.git
fixes bug 327719 "Passing a big double serialize a rounded double" patch by afatecha@idea.com.py r=dbaron sr=darin
This commit is contained in:
Родитель
679ffd2a50
Коммит
aed45f7b66
|
@ -410,6 +410,8 @@ class nsTString_CharT : public nsTSubstring_CharT
|
||||||
* Append the given float to this string
|
* Append the given float to this string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
NS_COM void AppendFloat( float aFloat );
|
||||||
|
|
||||||
NS_COM void AppendFloat( double aFloat );
|
NS_COM void AppendFloat( double aFloat );
|
||||||
|
|
||||||
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
||||||
|
|
|
@ -1261,7 +1261,7 @@ nsString::AppendInt( PRInt64 aInteger, PRInt32 aRadix )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
nsCString::AppendFloat( double aFloat )
|
nsCString::AppendFloat( float aFloat )
|
||||||
{
|
{
|
||||||
char buf[40];
|
char buf[40];
|
||||||
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
||||||
|
@ -1271,7 +1271,7 @@ nsCString::AppendFloat( double aFloat )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsString::AppendFloat( double aFloat )
|
nsString::AppendFloat( float aFloat )
|
||||||
{
|
{
|
||||||
char buf[40];
|
char buf[40];
|
||||||
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
||||||
|
@ -1280,4 +1280,24 @@ nsString::AppendFloat( double aFloat )
|
||||||
AppendWithConversion(buf);
|
AppendWithConversion(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsCString::AppendFloat( double aFloat )
|
||||||
|
{
|
||||||
|
char buf[40];
|
||||||
|
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
||||||
|
// locale-sensitive PR_snprintf or sprintf(3)
|
||||||
|
Modified_cnvtf(buf, sizeof(buf), 15, aFloat);
|
||||||
|
Append(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsString::AppendFloat( double aFloat )
|
||||||
|
{
|
||||||
|
char buf[40];
|
||||||
|
// Use Modified_cnvtf, which is locale-insensitive, instead of the
|
||||||
|
// locale-sensitive PR_snprintf or sprintf(3)
|
||||||
|
Modified_cnvtf(buf, sizeof(buf), 15, aFloat);
|
||||||
|
AppendWithConversion(buf);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
||||||
|
|
|
@ -513,6 +513,32 @@ PRBool test_appendint64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool test_appendfloat()
|
||||||
|
{
|
||||||
|
nsCString str;
|
||||||
|
double bigdouble = 11223344556.66;
|
||||||
|
static const char double_expected[] = "11223344556.66";
|
||||||
|
static const char float_expected[] = "0.01";
|
||||||
|
|
||||||
|
// AppendFloat is used to append doubles, therefore the precision must be
|
||||||
|
// large enough (see bug 327719)
|
||||||
|
str.AppendFloat( bigdouble );
|
||||||
|
if (!str.Equals(double_expected)) {
|
||||||
|
fprintf(stderr, "Error appending a big double: Got %s\n", str.get());
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
str.Truncate();
|
||||||
|
// AppendFloat is used to append floats (bug 327719 #27)
|
||||||
|
str.AppendFloat( 0.1f * 0.1f );
|
||||||
|
if (!str.Equals(float_expected)) {
|
||||||
|
fprintf(stderr, "Error appending a float: Got %s\n", str.get());
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return PR_TRUE;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,6 +736,7 @@ tests[] =
|
||||||
{ "test_set_length", test_set_length },
|
{ "test_set_length", test_set_length },
|
||||||
{ "test_substring", test_substring },
|
{ "test_substring", test_substring },
|
||||||
{ "test_appendint64", test_appendint64 },
|
{ "test_appendint64", test_appendint64 },
|
||||||
|
{ "test_appendfloat", test_appendfloat },
|
||||||
{ "test_findcharinset", test_findcharinset },
|
{ "test_findcharinset", test_findcharinset },
|
||||||
{ "test_rfindcharinset", test_rfindcharinset },
|
{ "test_rfindcharinset", test_rfindcharinset },
|
||||||
{ "test_stringbuffer", test_stringbuffer },
|
{ "test_stringbuffer", test_stringbuffer },
|
||||||
|
|
Загрузка…
Ссылка в новой задаче