552 changes: 552 additions & 0 deletions libc/src/__support/ryu_long_double_constants.h

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions libc/test/src/stdio/sprintf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,79 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
"231934194956788626761834746430104077432547436359522462253411168467463134"
"24896.000000");

written = __llvm_libc::sprintf(big_buff, "%Lf", 0xf.fffffffffffffffp+16380L);
ASSERT_STREQ_LEN(
written, big_buff,
"118973149535723176502126385303097020516906332229462420044032373389173700"
"552297072261641029033652888285354569780749557731442744315367028843419812"
"557385374367867359320070697326320191591828296152436552951064679108661431"
"179063216977883889613478656060039914875343321145491116008867984515486651"
"285234014977303760000912547939396622315138362241783854274391783813871780"
"588948754057516822634765923557697480511372564902088485522249479139937758"
"502601177354918009979622602685950855888360815984690023564513234659447638"
"493985927645628457966177293040780660922910271504608538808795932778162298"
"682754783076808004015069494230341172895777710033571401055977524212405734"
"700738625166011082837911962300846927720096515350020847447079244384854591"
"288672300061908512647211195136146752763351956292759795725027800298079590"
"419313960302147099703527646744553092202267965628099149823208332964124103"
"850923918473478612192169721054348428704835340811304257300221642134891734"
"717423480071488075100206439051723424765600472176809648610799494341570347"
"632064355862420744350442438056613601760883747816538902780957697597728686"
"007148702828795556714140463261583262360276289631617397848425448686060994"
"827086796804807870251185893083854658422304090880599629459458620190376604"
"844679092600222541053077590106576067134720012584640695703025713896098375"
"799892695455305236856075868317922311363951946885088077187210470520395758"
"748001314313144425494391994017575316933939236688185618912993172910425292"
"123683515992232205099800167710278403536014082929639811512287776813570604"
"578934353545169653956125404884644716978689321167108722908808277835051822"
"885764606221873970285165508372099234948333443522898475123275372663606621"
"390228126470623407535207172405866507951821730346378263135339370677490195"
"019784169044182473806316282858685774143258116536404021840272491339332094"
"921949842244273042701987304453662035026238695780468200360144729199712309"
"553005720614186697485284685618651483271597448120312194675168637934309618"
"961510733006555242148519520176285859509105183947250286387163249416761380"
"499631979144187025430270675849519200883791516940158174004671147787720145"
"964446117520405945350476472180797576111172084627363927960033967047003761"
"337450955318415007379641260504792325166135484129188421134082301547330475"
"406707281876350361733290800595189632520707167390454777712968226520622565"
"143991937680440029238090311243791261477625596469422198137514696707944687"
"035800439250765945161837981185939204954403611491531078225107269148697980"
"924094677214272701240437718740921675661363493890045123235166814608932240"
"069799317601780533819184998193300841098599393876029260139091141452600372"
"028487213241195542428210183120421610446740462163533690058366460659115629"
"876474552506814500393294140413149540067760295100596225302282300363147382"
"468105964844244132486457313743759509641616804802412935187620466813563687"
"753281467553879887177183651289394719533506188500326760735438867336800207"
"438784965701457609034985757124304510203873049485425670247933932280911052"
"604153852899484920399109194612991249163328991799809438033787952209313146"
"694614970593966415237594928589096048991612194498998638483702248667224914"
"892467841020618336462741696957630763248023558797524525373703543388296086"
"275342774001633343405508353704850737454481975472222897528108302089868263"
"302028525992308416805453968791141829762998896457648276528750456285492426"
"516521775079951625966922911497778896235667095662713848201819134832168799"
"586365263762097828507009933729439678463987902491451422274252700636394232"
"799848397673998715441855420156224415492665301451550468548925862027608576"
"183712976335876121538256512963353814166394951655600026415918655485005705"
"261143195291991880795452239464962763563017858089669222640623538289853586"
"759599064700838568712381032959192649484625076899225841930548076362021508"
"902214922052806984201835084058693849381549890944546197789302911357651677"
"540623227829831403347327660395223160342282471752818181884430488092132193"
"355086987339586127607367086665237555567580317149010847732009642431878007"
"000879734603290627894355374356444885190719161645514115576193939969076741"
"515640282654366402676009508752394550734155613586793306603174472092444651"
"353236664764973540085196704077110364053815007348689179836404957060618953"
"500508984091382686953509006678332447257871219660441528492484004185093281"
"190896363417573989716659600075948780061916409485433875852065711654107226"
"099628815012314437794400874930194474433078438899570184271000480830501217"
"712356062289507626904285680004771889315808935851559386317665294808903126"
"774702966254511086154895839508779675546413794489596052797520987481383976"
"257859210575628440175934932416214833956535018919681138909184379573470326"
"940634289008780584694035245347939808067427323629788710086717580253156130"
"235606487870925986528841635097252953709111431720488774740553905400942537"
"542411931794417513706468964386151771884986701034153254238591108962471088"
"538580868883777725864856414593426212108664758848926003176234596076950884"
"9149662444156604419552086811989770240.000000");

written = __llvm_libc::sprintf(big_buff, "%.10Lf", 1e-10L);
ASSERT_STREQ_LEN(written, big_buff, "0.0000000001");

Expand Down Expand Up @@ -1749,6 +1822,9 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {

written = __llvm_libc::sprintf(buff, "%.9Le", 1000000000500000000.0L);
ASSERT_STREQ_LEN(written, buff, "1.000000000e+18");

written = __llvm_libc::sprintf(buff, "%Le", 0xf.fffffffffffffffp+16380L);
ASSERT_STREQ_LEN(written, buff, "1.189731e+4932");
#endif

// TODO: Fix long doubles (needs bigger table or alternate algorithm.)
Expand Down Expand Up @@ -2378,6 +2454,9 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {

// Length Modifier Tests.

written = __llvm_libc::sprintf(buff, "%Lg", 0xf.fffffffffffffffp+16380L);
ASSERT_STREQ_LEN(written, buff, "1.18973e+4932");

// TODO: Uncomment the below tests after long double support is added
/*
written = __llvm_libc::sprintf(buff, "%Lf", 1e100L);
Expand Down
4 changes: 2 additions & 2 deletions libc/utils/mathtools/ryu_tablegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ def print_negative_table_for_idx(idx):
)
else:
print("static const uint64_t POW10_SPLIT[][" + str(MID_INT_SIZE // 64) + "] = {")
for idx in range(0, POSITIVE_ARR_SIZE):
for idx in range(0, POSITIVE_ARR_SIZE + 1):
num_size = print_positive_table_for_idx(idx)
positive_size_arr[idx] = acc
acc += num_size
positive_size_arr[idx + 1] = acc
print("};")

print(
Expand Down