forked from OSchip/llvm-project
[libc] tweak strtof errno behavior
When strtof/d/ld return a subnormal number they may set errno to ERANGE. This change makes this behavior more consistent by making any decimal number converting to a subnormal set errno to ERANGE. This brings it in line with hexadecimals, which currently only set errno to ERANGE if the number is truncated when converting to a subnormal. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D113626
This commit is contained in:
parent
18da0c0a28
commit
4cdf9884b6
|
@ -308,6 +308,10 @@ simpleDecimalConversion(const char *__restrict numStart,
|
||||||
++exp2;
|
++exp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exp2 == 0) {
|
||||||
|
errno = ERANGE; // NOLINT
|
||||||
|
}
|
||||||
|
|
||||||
*outputMantissa = finalMantissa;
|
*outputMantissa = finalMantissa;
|
||||||
*outputExp2 = exp2;
|
*outputExp2 = exp2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,8 +206,8 @@ TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicExponents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicSubnormals) {
|
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicSubnormals) {
|
||||||
SimpleDecimalConversionTest<double>("1e-320", 0x7e8, 0);
|
SimpleDecimalConversionTest<double>("1e-320", 0x7e8, 0, ERANGE);
|
||||||
SimpleDecimalConversionTest<double>("1e-308", 0x730d67819e8d2, 0);
|
SimpleDecimalConversionTest<double>("1e-308", 0x730d67819e8d2, 0, ERANGE);
|
||||||
SimpleDecimalConversionTest<double>("2.9e-308", 0x14da6df5e4bcc8, 1);
|
SimpleDecimalConversionTest<double>("2.9e-308", 0x14da6df5e4bcc8, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64SubnormalRounding) {
|
||||||
// but this is the shortest string that results in the maximum subnormal that
|
// but this is the shortest string that results in the maximum subnormal that
|
||||||
// I found.
|
// I found.
|
||||||
SimpleDecimalConversionTest<double>("2.225073858507201e-308", 0xfffffffffffff,
|
SimpleDecimalConversionTest<double>("2.225073858507201e-308", 0xfffffffffffff,
|
||||||
0);
|
0, ERANGE);
|
||||||
|
|
||||||
// Same here, if you were to extend the max subnormal out for another 800
|
// Same here, if you were to extend the max subnormal out for another 800
|
||||||
// digits, incrementing any one of those digits would create a normal number.
|
// digits, incrementing any one of those digits would create a normal number.
|
||||||
|
@ -227,7 +227,8 @@ TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64SubnormalRounding) {
|
||||||
|
|
||||||
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion32SpecificFailures) {
|
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion32SpecificFailures) {
|
||||||
SimpleDecimalConversionTest<float>(
|
SimpleDecimalConversionTest<float>(
|
||||||
"1.4012984643248170709237295832899161312802619418765e-45", 0x1, 0);
|
"1.4012984643248170709237295832899161312802619418765e-45", 0x1, 0,
|
||||||
|
ERANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
|
TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
|
||||||
|
|
|
@ -82,7 +82,8 @@ TEST_F(LlvmLibcStrToFTest, DecimalsWithRoundingProblems) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LlvmLibcStrToFTest, DecimalSubnormals) {
|
TEST_F(LlvmLibcStrToFTest, DecimalSubnormals) {
|
||||||
runTest("1.4012984643248170709237295832899161312802619418765e-45", 55, 0x1);
|
runTest("1.4012984643248170709237295832899161312802619418765e-45", 55, 0x1,
|
||||||
|
ERANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LlvmLibcStrToFTest, DecimalWithLongExponent) {
|
TEST_F(LlvmLibcStrToFTest, DecimalWithLongExponent) {
|
||||||
|
|
Loading…
Reference in New Issue