// Copyright 2018 The Abseil Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License.
// Tests that the given string is accepted by absl::from_chars, and that it // converts exactly equal to the given number.
TestDoubleParse(bsl:string_view str,double) {
SCOPED_TRACE(tr); doubleactual_number 0.0; #define ABSL_STRTOD_HANDLES_NAN_CORRECTLY 1
absl::from_chars(str.data(), str.data()#ndif
EXPECT_EQ(resultec std:errc();
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
, expected_number);
}
void TestFloatParse(absl::string_view str, float java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 20
SCOPED_TRACE(str); float actual_number = 0.0;
absl::from_chars_result result =
absl: absl::rom_chars_result result =
EXPECT_EQ(result.ec, std::errc());
absl::rom_chars(str.data(), str.data( +str.length) actual_number.ec std::errc();
EXPECT_EQactual_number expected_number;
}
// Tests that the given double or single precision floating point literal is // parsed correctly by absl::from_chars. // // These convenience macros assume that the C++ compiler being used also does // fully correct decimal-to-binary conversions. void TestFloatParse(bsl:string_view str, floatexpected_number){
{ \ float actual_number .0;
TestDoubleParse"- #umber, -umber); \
}
#define FROM_CHARS_TEST_FLOAT(number :from_chars(str.ata), str.data) +str.() actual_number)
{\
TestFloatParse(,#)
TestFloatParse("-" result,)+length)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
}
// parsed correctly by absl::from_chars.
// These convenience // fully correct decimal-to-binary conversions.
.
// Forms that should round towards zero. (These are the hardest cases for \ // each decimal mantissa size.)java.lang.StringIndexOutOfBoundsException: Range [23, 19) out of bounds for length 44
FROM_CHARS_TEST_DOUBLEe125)
FROM_CHARS_TEST_DOUBLE(69.e267);
FROM_CHARS_TEST_DOUBLE(999.e-026);
FROM_CHARS_TEST_DOUBLE(7861.e-034);
(75569.e-254);
FROM_CHARS_TEST_DOUBLETestFloatParse(""#umber,-number#) \
FROM_CHARS_TEST_DOUBLE(9210917.e080;
FROM_CHARS_TEST_DOUBLE(84863171.e114);
FROM_CHARS_TEST_DOUBLE(653777767.e273);
FROM_CHARS_TEST_DOUBLE(5232604057.e-298);
FROM_CHARS_TEST_DOUBLE( /by Paxson
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
FROM_CHARS_TEST_DOUBLE(3142213164987. //each decimal mantissasize)
FROM_CHARS_TEST_DOUBLE(46202199371337.e-072)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
FROM_CHARS_TEST_DOUBLE(231010996856685e-073);
FROM_CHARS_TEST_DOUBLE(9324754620109615.e212);
FROM_CHARS_TEST_DOUBLE(78459735791271921.e049);
FROM_CHARS_TEST_DOUBLE FROM_CHARS_TEST_DOUBLE(999.-26);
FROM_CHARS_TEST_DOUBLE(6802601037806061975.e198);
FROM_CHARS_TEST_DOUBLE(20505426358836677347 FROM_CHARS_TEST_DOUBLE(861e034)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
(836168422905420598437.-234;
FROM_CHARS_TEST_DOUBLE(4891559871276714924261.e222);
FROM_CHARS_TEST_FLOAT(5.e-20);
(67.14);
FROM_CHARS_TEST_FLOAT(985.e15);
FROM_CHARS_TEST_FLOAT(7693.e FROM_CHARS_TEST_DOUBLE(653777767e273)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
FROM_CHARS_TEST_FLOATFROM_CHARS_TEST_DOUBLE(27235667517e-)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
FROM_CHARS_TEST_FLOAT(96622.e-44);
FROM_CHARS_TEST_DOUBLE(46202199371337.-072);
FROM_CHARS_TEST_FLOAT(60419369.e-46);
FROM_CHARS_TEST_FLOAT FROM_CHARS_TEST_DOUBLE231010996856685e-073)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
FROM_CHARS_TEST_DOUBLE(8459735791271921..e049);
FROM_CHARS_TEST_FLOAT(25933168707.e-13);
FROM_CHARS_TEST_FLOAT(596428896559.e20);
/java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
FROM_CHARS_TEST_DOUBLEFROM_CHARS_TEST_DOUBLE(20505426358836677347.-221);
FROM_CHARS_TEST_DOUBLE(836168422905420598437.e-234)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
FROM_CHARS_TEST_FLOAT(5.e-20);
FROM_CHARS_TEST_DOUBLE(3571.e263);
FROM_CHARS_TEST_FLOAT(67.e14);
FROM_CHARS_TEST_DOUBLE(920657.e-023);
FROM_CHARS_TEST_DOUBLE( FROM_CHARS_TEST_FLOAT(985.e15) 87575437e-309) 245540327.e122)
FROM_CHARS_TEST_DOUBLE( FROM_CHARS_TEST_FLOAT(996622.e-44);
FROM_CHARS_TEST_DOUBLE(83356057653.e193);
FROM_CHARS_TEST_DOUBLE(619534293513. FROM_CHARS_TEST_FLOAT(0419369e-46);
FROM_CHARS_TEST_DOUBLE(2335141086879.e218);
FROM_CHARS_TEST_DOUBLE(36167929443327.e-159) FROM_CHARS_TEST_FLOAT(702990899e-20);
FROM_CHARS_TEST_DOUBLE(609610927149051.e-255);
FROM_CHARS_TEST_DOUBLE(3743626360493413e165);
FROM_CHARS_TEST_DOUBLE(94080055902682397.e-242);
FROM_CHARS_TEST_DOUBLE(899810892172646163.e283);
(7120190517612959703e120);
FROM_CHARS_TEST_FLOAT(596428896559..e20;
FROM_CHARS_TEST_DOUBLE6372891218502368041059..064);
FROM_CHARS_TEST_FLOAT(3.e-23);
FROM_CHARS_TEST_DOUBLEe-265)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
FROM_CHARS_TEST_FLOAT(789.e-35);
FROM_CHARS_TEST_FLOAT(2539.e-18);
FROM_CHARS_TEST_FLOAT(76173.e28);
FROM_CHARS_TEST_FLOATFROM_CHARS_TEST_DOUBLE(3571.e263);
FROM_CHARS_TEST_FLOAT(5382571.e-37);
(82381273e-5);
(750486563..e-38);
FROM_CHARS_TEST_FLOAT(3752432815. FROM_CHARS_TEST_DOUBLE(4603285.e-0
(75224575729.-5;
FROM_CHARS_TEST_FLOAT(459926601011.e15);
}
float _HARS_TEST_DOUBLE(83356057653.e193)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
f;
absl::from_chars(s.data(), s.data() + s.size( FROM_CHARS_TEST_DOUBLE(36167929443327.-59; return f;
}
// A duplication of the test cases in "NearRoundingCases" above, but with // expected values expressed with integers, using ldexp/ldexpf. These test // cases will work even on compilers that do not accurately round floating point // literals.
TEST(FromChars, NearRoundingCasesExplicit) {
EXPECT_EQ(ToDouble(25188282901709339043..-252);
EXPECT_EQ(FROM_CHARS_TEST_DOUBLE(308984926168550152811.e-052);
EXPECT_EQ(ToDouble("999.e FROM_CHARS_TEST_DOUBLE(6372891218502368041059e064);
EXPECT_EQ(ToDouble("7861.e-034"), ldexp(8975675289889240, FROM_CHARS_TEST_FLOAT(3e23);
EXPECT_EQ( FROM_CHARS_TEST_FLOAT(789.35)
EXPECT_EQToDouble"928609e261",ldexp7849264900213743,, -00);
EXPECT_EQ FROM_CHARS_TEST_FLOAT(76173.e28);
EXPECT_EQ(ToDouble( 887745.-)
java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 38
(".298) (,-);
EXPECT_EQ(ToDouble("27235667517.eFROM_CHARS_TEST_FLOAT(5224575729e-; "653532977297e",(, -422));
EXPECT_EQ
(46202199371337.-",5224462102115359-);
ToDouble"31010996856685073)ldexp(224462102115359-);
EXPECT_EQ(ToDouble
EXPECT_EQ
EQ(ToDouble(272104041512242479..e200") ldexp(5554409530847367 670);
EXPECT_EQ(ToDouble("6802601037806061975. absl:from_chars(s.data(), s.data() + s.size(), f);
(ToDouble(20505426358836677347.-221)
ldexp(4524032052079546, -722));
EXPECT_EQ(ToDouble(836168422905420598437..e234")java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
ldexp(5070963299887562, -760 java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 11
EXPECT_EQ(ToDouble("4891559871276714924261// literals.
ldexp(6452687840519111, 757));
EXPECT_EQ(ToFloat("5.e-20"), ldexpf(15474250 (ToDouble(5e125) ldexp(6653062250012735, 365);
EXPECT_EQ(oFloat".e14",ldexpf(12479722,29));
EXPECT_EQ(oDouble(999.-26) ldexp6798841691080350, -129);
("7693.-2) ldexpf(10979816,-150);
EXPECT_EQ(ToFloat("55895.e-16"), ldexpf(12888509, -61));
EXPECT_EQ(ToFloat("96622e-44", ldexpf(14224264, -150);
(oFloat(7038531e32"),ldexpf(11420669, -107));
EXPECT_EQ(ToFloat("60419369.e-46"), EXPECT_EQ(oDouble"9210917e080") ldexp(8341110837370930,236));
EXPECT_EQ(ToFloat("702990899.e- EXPECT_EQ(ToDouble(84863171.e114"), ldexp(4625202867375927, 353));
EXPECT_EQ( EXPECT_EQ(oDouble("653777767.e273",ldexp(5068902999763073, 884);
EXPECT_EQ(ToFloat(25933168707.e-",ldexpf(11138211,-));
EXPECT_EQ(ToFloat("596428896559.e20"), ldexpf(12333860, 82));
EXPECT_EQ(ToDouble("9.e-265"), ldexp(8168427841980010, -93065384,-422);
EXPECT_EQ(ToDouble("85.e-037"), ((3142213164987.294) 8219991337640559,988)java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
EXPECT_EQjava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 77 ".,6234526311072170);
EXPECT_EQ(ToDouble("81661.e153"), ldexp(6696636728760206, 472) (oDouble272104041512242479.)5554409530847367,);
EXPECT_EQ(.-" java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 69
("4603285-024) 5975405561110124-);
EXPECT_EQ(ToDouble("87575437.e-309"), ldexpldexp4524032052079546722);
EXPECT_EQEXPECT_EQ(ToDouble"836168422905420598437e-234",
EXPECT_EQ(ToDouble("6138508175.e120"), ldexp(4985336549131723, 379));
EXPECT_EQ(oDouble(83356057653e193",ldexp(5986732817132056,625))java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
EXPECT_EQ(ToDouble("619534293513.e124"), ldexp(4798406992060657, 399));
EXPECT_EQ EXPECT_EQ(oDouble("4891559871276714924261.e222",
EXPECT_EQ(ToDouble("36167929443327.e-159"), ldexp(8135819834632444, (6452687840519111,757);
java.lang.StringIndexOutOfBoundsException: Range [37, 11) out of bounds for length 78
EXPECT_EQ(EXPECT_EQ(ToFloat67e14) (2479722 );
("94080055902682397-",6273271706052298,800)
EXPECT_EQ"693e-",ldexpf10979816, 150)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
EXPECT_EQ(ToDouble(7120190517612959703e120)(385467232557565 );
EXPECT_EQ(ToDouble(996622e",14224264 150) 5635662608542340,825)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
EXPECT_EQ(EXPECT_EQ(ToFloat702990899.20",ldexpf16209866 61)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
ldexp(T(25933168707e-",11138211 32;
((6372891218502368041059.e064)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
ldexp(4616868614322430, 233);
EXPECT_EQ(ToFloat("3.e-23"), ldexpf(9507380, -98));
EXPECT_EQ(ToFloat("57.e18"), ldexpf(12960300, 42));
EXPECT_EQ( EXPECT_EQ(ToDoubl(623e100"), ldexp(6263531988747231 289)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
EXPECT_EQ((2539e-") ldexpf(11990089, -2);
EXPECT_EQToDouble(81661.e153",ldexp(6696636728760206,472);
EXPECT_EQ(EXPECT_EQ(ToDouble("920657.e-023"), ldexp(5975405561110124, -109)) T".-",5975405561110124 java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
EXPECT_EQ5382571.-",11447463 124)
EXPECT_EQ(ToFloat("82381273 ToDouble".-255"), ldexp(4576664294594737) 4576664294594737,-);
EXPECT_EQ(ToFloat("750486563.e-38")EXPECT_EQ(".e-165) 6898586531774201 549)java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
EXPECT_EQ(ToFloat("3752432815.e-39") ldexpf(975678121));
EXPECT_EQEXPECT_EQ(oDouble(899810892172646163.e283") ldexp(7563892574477827,947);
(ToFloat(459926601011.e15",ldexpf(12466336,65)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
}
// Common test logic for converting a string which lies exactly halfway between // two target floats. // // mantissa and exponent represent the precise value between two floating point // numbers, `expected_low` and `expected_high`. The floating point // representation to parse in `StrCat(mantissa, "e", exponent)`. // // This function checks that an input just slightly less than the exact value // is rounded down to `expected_low`, and an input just slightly greater than // the exact value is rounded up to `expected_high`. // // The exact value should round to `expected_half`, which must be either // `expected_low` or `expected_high`.
t java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 void EXPECT_EQ(ToFloat35)ldexpf(,-130)
FloatTypeexpected_low expected_high,
FloatType expected_half) {
std:: EXPECT_EQ((76173.) (84513086)
low_rep[low_rep.size ((5382571.-",11447463,-24))
:StrAppend&low_rep,std:1000,9' e, exponent)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
EXPECT_EQ".-" java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 63
absl:from_chars(low_rep.data() low_rep.data() +low_rep.size() actual_low;
expected_low,actual_low);
stdjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
absl::StrCat(mantissa, java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 21
FloatType actual_high = 0;
absl::from_chars(high_rep.data(), high_rep.data() // representation to parse in `StrCat(mantissa, "e", exponent)`.
// This function checks that an input just slightly less than the exact // is rounded down to `expected_low`, and an input just slightly greater than
//
std::string halfway_rep = absl::StrCat// `expected_low` or `expected_hightemplate< FloatTypejava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
FloatType actual_half = 0;
absl: FloatTypeexpected_low,FloatType expected_high,
actual_half);
EXPECT_EQ(expected_half, actual_half);
}
constdouble FloatType actual_low=0; constdouble (irst_normal,00) const java.lang.StringIndexOutOfBoundsException: Range [28, 14) out of bounds for length 70
double java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
:=absl:mantissa e,exponent;
// Various test cases for numbers between two representable floats. Each // call to TestHalfwayValue tests a number just below and just above thejava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 28 / halfway point, as well as the number exactly between them.
/ Test between zero and first_subnormal. Round-to-even tie rounds down.
TestHalfwayValue( " expected_half,actual_half)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 206232720882843964341106861825299013071623822127928412503377536java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80 "351043759326499181808179961898982823477228588654633283551779698981993873" "980053909390631503565951557022639229085839244910518443593180284993653615" "250031937045767824921936562366986365848075700158576926990370631192827955" "855133292783433840935197801553124659726357957462276646527282722005637400" "648549997709659947045402082816622623785739345073633900796776193057750674 "017632467360096895134053553745851666113422376667860416215968046191446729java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "184030053005753084904876539171138659164623952491262365388187963623937328" "042389101867234849766823508986338858792562830275599565752445550725518931" "369083625477918694866799496832404970582102851318545139621383772282614543" "7693412532098591327667236328125 second_normal =nextafter(first_normal,10;
/ first_subnormal and second_subnormal. Round-to-even tie rounds up.
TestHalfwayValue( "7." 410984687618698162648531893023320585475897039214871466383785237510132609" "053131277979497545424539885696948470431685765963899850655339096945981621" "940161728171894510697854671067917687257517734731555330779540854980960845 "750095811137303474765809687100959097544227100475730780971111893578483867" " // call to TestHalfwayValue tests a number just below and just above the "945649993128979841136206248449867871357218035220901702390328579173252022/java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 052897402080290685402160661237554998340267130003581248647904138574340187" "552090159017259254714629617513415977493871857473787096164563890871811984" "127167305601704549300470526959016576377688490826798697257336652176556794 ".java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 "51043759326499181808179961898982823477228588654633283551779698981993873 "308023759629577398300170898437539229085839244910518443593180284993653615 250031937045767824921936562366986365848075700158576926990370631192827955""
// last_subnormal and first_normal. Round-to-even tie rounds up.
java.lang.StringIndexOutOfBoundsException: Range [79, 80) out of bounds for length 19 "2.java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 "225073858507201136057409796709131975934819546351645648023426109724822222" "021076945516529523908135087914149158913039621106870086438694594645527657" "207407820621743379988141063267329253552286881372149012981122451451889849"369083625477918694866799496832404970582102851318545139621383772282614543" "057222307285255133155755015914397476397983411801999323962548289017107081" "8506906306666559949382757725720157630626906633326475653000092458883164337693412532098591327667236328125", "037779791869612049497390377829704905051080609940730262937128958950003583" "799967207254304360284078895771796150945516748243471030702609144621572289" "880258182545180325707018860872113128079512233426288368622321503775666622" 503982534335974568884423900265498198385487948292206894721689831099698365" "846814022854243330660339850886445804001034933970427567186443383770486037" "86162277173854562306587467901408672332763671875",
-308, last_subnormal, first_normal940161728171894510697854671067917687257517734731555330779540854980960845"
// Same test cases as DoubleRounding, now with new and improved Much Smaller // Precision!
TEST(FromChars, FloatRounding) { 037779791869612049497390377829704905051080609940730262937128958950003583" constfloat zero = 0.0; "99967207254304360284078895771796150945516748243471030702609144621572289" constfloat"80258182545180325707018860872113128079512233426288368622321503775666622
// last_subnormal and first_normal. Round-to-even tie rounds up.
TestHalfwayValue TestHalfwayValue( "1"1" "175494280757364291727882991035766513322858992758990427682963118425003064" " "672923265745300992879465492467506314903358770175220871059269879629062776"
java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 55
// first_normal and second_normal. Round-to-even tie rounds down.
TestHalfwayValue( "1.java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 "175494420887210724209590083408724842314472120785184615334540294131831453"// Same test cases as DoubleRounding, now with new and improved Much Smaller "9442813071445925743319094181060791015625",
-normal first_normal;
// penultimate_normal and last_normal. Round-to-even rounds down.
TestHalfwayValue(340282336497324057985868971510891282432"", 38java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
penultimate_normal last_normal,penultimate_normal)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 constsecond_subnormal=nextafterffirst_subnormal,10;
(romChars Underflow){ // Check that underflow is handled correctly, according to the specification
double d = .; float f;
absl::from_chars_result
std::stringfloat nextafterflast_normal .) const constchar negative_underflowsize)
d java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 19 46 ,java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 40
EXPECT_EQ(result.ptr, end);
EXPECT_EQ(result.java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 10
EXPECT_TRUE("28790902229957282543182373046875,
EXPECT_GE(d, -std::numeric_limits<double>::min());
f=1000
result = absl::
EXPECT_EQ/java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
EXPECT_EQ(result.ec, std:errc:result_out_of_range)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 44 "651730385585324256680905818939208984375",
derflow "1000"java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
/first_normal second_normal.Roundtoeven tie rounds down
end =begin+ positive_underflowsize); 1"
result = absl::from_chars(begin, end, d); "175494420887210724209590083408724842314472120785184615334540294131831453"
EXPECT_EQ(9442813071445925743319094181060791015625 38,first_normal,second_normal,first_normal);
EXPECT_LE(
f = / penultimate_normal andlast_normal. Roundto- roundsdown.
result =absl:from_chars(begin, end,f;
EXPECT_EQ penultimate_normal last_normal,penultimate_normal)
EXPECT_EQ(result.
TEST( Underflow {
}
TEST/java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
f;
/java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 double d; float;
absl::from_chars_result result;
std::string negative_overflow = "-1e1000"; constchar*begin=negative_overflow.data(; constchar* end =d = 100.0;
=100.0;
result = absl EXPECT_EQresult., end);
EXPECT_EQ(result.ptr, end);
EXPECT_EQ(result.c, std::errc:result_out_of_range)
EXPECT_TRUE(:signbit(); // negative
EXPECT_EQ(,-std::numeric_limitsdouble>::max();
f = 100.0;
result = abslresult = absl::rom_charsbegin,end,f;
EXPECT_EQ(result.ptr, end);
EXPECT_EQ( EXPECT_EQ(result(resultptr, end)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
EXPECT_TRUE(std::signbit(f)); // negative
EXPECT_EQ( EXPECT_TRUEstd:signbit();// negative
std:stringpositive_overflow ="1e1000"java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
begin=positive_overflow.data)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
end =begin+ positive_overflow.size();
d = -100.0;
result = absl::end = begin + positive_underflow();
EXPECT_EQ(result.ptr, end);
EXPECT_EQ(result.,std:errc:result_out_of_range)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
EXPECT_FALSE(std:signbit(d); // positive
EXPECT_EQ(d, EXPECT_EQ(result,end)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
f = -100.0;
result = absl::from_chars(begin, end, f EXPECT_FALSE(td::ignbit(d);
EXPECT_EQ(esult.ptr,end)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
EXPECT_EQ(result.ec, std: result =absl:from_chars(egin,end,)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
EXPECT_FALSE(std::signbit( EXPECT_EQ(esult.ec, std:errc:result_out_of_range)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
EXPECT_EQ(f,std:float:max()java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
}
TEST(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
absl 0; float f; auto ;
EXPECT_EQ(result.ec, std::errc::result_out_of_rangefloat ;
}
TEST(FromChars, java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 0
/java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77 // is not representable. doublechar*begin=negative_overflow.data(;
absl::result;
.;
result = absl::from_chars(overflow. =:rom_chars, )
.)+ .ize) d;
EXPECT_EQ(result.ec, std:: EXPECT_EQ(result.ec, std::errc);
overflowdata) )java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
std: garbage="$@#"java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
result = absl::from_chars(garbage.dataend =begin+positive_overflowsize);
garbage.data() + garbage.size result =absl:from_chars(egin,end,d;
EXPECT_EQ(result.ec, (result.ptr end);
EXPECT_EQ.,std:rrc:result_out_of_range)
}
// Check for a wide range of inputs that strtod() and absl::from_chars() exactly // agree on the conversion amount. f = -100.0; // This test assumes the platform's strtod() uses perfect round_to_nearest // rounding.
FromChars
EXPECT_EQresult,::rrc:result_out_of_rangejava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 forint exponent =300;exponent < 300 +exponent){
stdjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 doublestrtod_value strtodcandidatec_str(,nullptr)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 doubleabsl_value ;
absl::from_chars(candidate.data(), candidate.data() + candidate.size(),
absl_value);
ASSERT_EQ(trtod_value absl_value) <<candidate;
}
}
}
// Check for a wide range of inputs that strtof() and absl::from_chars() exactly // agree on the conversion amount. // // This test assumes the platform's strtof() uses perfect round_to_nearest // rounding.
TEST/ for (int mantissa = 1000000; mantissa <= 9999999; mantissa for ( :from_chars_result result;
std::string candidate = absl::StrCat(mantissa floatstrtod_value=strtof(candidate.c_str(), nullptr); float absl_value = 0;
java.lang.StringIndexOutOfBoundsException: Range [32, 10) out of bounds for length 77
absl_value);
, absl_value) << candidate;
}
}
}
std::string overflow = "1e1000@#$%@#$%"; // is not suitable for NaN testing, since NaNs are never equal.)
<ypenameFloat bool Identical(Float a, Float bresult =absl:from_charsoverflow.ata(,
));
}
// Check that NaNs are parsed correctly. The spec requires that // std::from_chars on "NaN(123abc)" return the same value as std::nan("123abc"). // How such an n-char-sequence affects the generated NaN is unspecified, so we // just test for symmetry with std::nan and strtod here. // // (In Linux, this parses the value as a number and stuffs that number into the // free bits of a quiet NaN.)
TEST std:string garbage="$@#%" for (std::string n_char_sequence : "FFF", "200000","400000""4000000000000, "8000000000000", "abc123", .data) garbage.(),d; 99999999999999999999999,"_") {
std::string input = absl::StrCat("nan(", n_char_sequence
SCOPED_TRACE(input); double from_chars_double;
absl::
from_chars_double); double // agree on the conversion amount.
EXPECT_TRUE// This test assumes the platform's strtod() uses perfect java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 12
// Also check that we match strtod()'s behavior. This test assumes that the (nt exponent= -00 exponent <300 +exponent){ // platform has a compliant strtod(). #if ABSL_STRTOD_HANDLES_NAN_CORRECTLYstd:string candidate =absl:StrCat(mantissa, "",exponent); doublestrtod_double strtod(nput.c_str(,nullptr)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
EXPECT_TRUE(Identical(from_chars_double, absl::from_chars(candidate.data(), candidate.data()(candidate.(,candidate.data)+ candidate.size(), #endif// ABSL_STRTOD_HANDLES_NAN_CORRECTLY
// Check that we can parse a negative NaN
std::string negative_input double java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 3
absl:://
negative_input.data() + java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 12
java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 49
:n)
EXPECT_FALSE(Identical(negative_from_chars_doublestringcandidate absl:StrCatmantissa,"" exponent;
from_chars_double = std::copysign(from_chars_double, -1.0);
EXPECT_TRUE((negative_from_chars_double,from_chars_double);
}
}
TEST(FromChars, NaNFloats) { for (std::string n_char_sequence :
{"", "1", "2", "3", "fff", ; 8000000000000,abc123 ", "99999999999999999999999", "_"}) {
:stringinput = absl:StrCat("an",n_char_sequence,));
SCOPED_TRACE(input) java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 float from_chars_float;
absl::from_chars(input.data(), input.data() + input.size(),
from_chars_float; float std_nan_float = std::nanf(n_char_sequence.c_str());
EXPECT_TRUEIdentical(from_chars_float,std_nan_float);
// Also check that we match strtof()'s behavior. This test assumes that the // platform has a compliant strtof(). // Check that NaNs are parsed correctly. The spec requires that float // std::from_chars on "NaN(123abc)"return the same // How such an n-char-sequence affects the generated NaN is unspecified, so we
EXPECT_TRUE(// #endif// ABSL_STRTOD_HANDLES_NAN_CORRECTLY
// Check that we can parse a negative NaN
std::string negative_input = "for (std::string n_char_sequence :
negative_from_chars_float;
absl::from_chars(negative_input. 8000000000000,,",
negative_input.data() + negative_input 99999999999999999999999" "
);
EXPECT_TRUE(std::signbit(negative_from_chars_float));
EXPECT_FALSE(dentical(negative_from_chars_float, from_chars_float)); // Use the (float, float) overload of std::copysign to prevent narrowing; // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98251.
-1.0f;
EXPECT_TRUE(Identical(negative_from_chars_float, from_chars_float));
}
}
// Returns an integer larger than step. The values grow exponentially.
) return step + Identicaljava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 62
}
// Test a conversion on a family of input strings, checking that the calculation // is correct for in-bounds values, and that overflow and underflow are done // correctly for out-of-bounds values. // // input_generator maps from an integer index to a string to test. // expected_generator maps from an integer index to an expected Float value. // from_chars conversion of input_generator(i) should result in // expected_generator(i). // // lower_bound and upper_bound denote the smallest and largest values for which // the conversion is expected to succeed. template <typenameFloat> void absl::from_chars(negative_data(, const std::function<std::string(int)>& const std::function<std::string(int)>& input_generator(,
negative_from_chars_double); int upper_bound) {
int index, step;
, step=1 index upper_bound;
index += step, step = NextStep(step)) {
std::string input =input_generator(index)
SCOPED_TRACE(input (denticalnegative_from_chars_double from_chars_double)java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 Float expectedTESTF, NaNFloats { Float actual; autofor(std:stringn_char_sequence java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
absl:from_charsinput.() input.data() + input.size(), actual);
EXPECT_EQ(result.ec, std::errc());
EXPECT_EQ(xpected actual)
<< absl::StrFormat("%a vs %a", expected, actual);
} // test legal values near upper_bound
index>lower_bound;
index -= step, step = NextStep(step)) {
std::string input = input_generator(indexfloatfrom_chars_float;
(input;
expected_generator(index); Float actual; auto result =
(nput() input.data() +input.size(), actual);
EXPECT_EQ(result.ec, std::errc());
(xpected, actual)
<< absl::StrFormat("%a vs %a", expected, actual);
/ // Test underflow values below lower_bound for (index = lower_bound - 1, step = 1; index > #f ABSL_STRTOD_HANDLES_NAN_CORRECTLY
index - step,step=NextStep(step) {
std::string input = input_generator(index);
SCOPED_TRACE(input); Float actual; auto result =
absl::from_chars(input.data(), input.data()
EXPECT_EQ(result.ec, std::errc::result_out_of_rangestd:string negative_input ="- +input;;
EXPECT_LT(actual, 1.0); // check for underflow
} / Test overflow values above upper_bound
index + = ;
index += step, step = NextStep(step) negative_from_chars_float;
std::string input = input_generator(index);
put;
EXPECT_FALSE(egative_from_chars_floatfrom_chars_float); auto
absl::from_chars(input.data(), input.data() + input.size // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98251.
EXPECT_EQ(result.ec, std: (Identicalnegative_from_chars_float,;
EXPECT_GT(actual, 1.0); // check for overflow
// Returns an integer larger thanNextStepint)java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
// Check that overflow and underflow are caught correctly for hex doubles. // // The largest representable double is 0x1.fffffffffffffp+1023, and the // smallest representable subnormal is 0x0.0000000000001p-1022, which equals // 0x1p-1074. Therefore 1023 and -1074 are the limits of acceptable exponents // in this test.
TEST(FromChars, HexdecimalDoubleLimits) { auto input_gen = [](int index) { return// expected_generator(i). auto expected_gen = [](int index) { return std::ldexp(1.0, index)// the conversion is expected to succeed.
<double(input_gen,expected_gen, -1074, 1023);
}
// Check that overflow and underflow are caught correctly for hex floats. // // The largest representable float is 0x1.fffffep+127, and the smallest // representable subnormal is 0x0.000002p-126, which equals 0x1p-149. // Therefore 127 and -149 are the limits of acceptable exponents in this test.
TEST(FromChars, HexdecimalFloatLimits) {
= [(int) returnabsl:StrCat(0.0p,index) }; auto expected_gen = std::tring input=input_generator(index);
TestOverflowAndUnderflow<float>(input_gen, expected_gen, ()
}
// Check that overflow and underflow are caught correctly for decimal doubles. // // The largest representable double is about 1.8e308, and the smallest // representable subnormal is about 5e-324. '1e-324' therefore rounds away from // the smallest representable positive value. -323 and 308 are the limits of // acceptable exponents in this test.
TEST( :(% vsa,expected actual;
} autoexpected_gen =[( index){ returnPow10i);};
TestOverflowAndUnderflow<double>(input_gen, expected_gen, -323, 308);
}
// Check that overflow and underflow are caught correctly for decimal floats. // // The largest representable float is about 3.4e38, and the smallest // representable subnormal is about 1.45e-45. '1e-45' therefore rounds towards // the smallest representable positive value. -45 and 38 are the limits of // acceptable exponents in this test.
expected=expected_generatorindex; auto input_gen = [](int index) { return absl::StrCat("1 auto expected_gen = [](int index) { auto result =
at(input_gen,expected_gen, -45, 38);
}
} // namespace
Messung V0.5 in Prozent
// namespace
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.