-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some test cases for printing and parsing floats
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import math | ||
|
||
def print_values(values): | ||
for v in values: | ||
# Avoiding doing just 'v' as we want this test to work in Python and Kuroko with identical results | ||
# and Python will try to reduce the number of digits to the minimum required for disambiguity, which | ||
# we don't currently support. | ||
print(v.__format__('.16g'),v.__format__('f'),v.__format__('e'),v.__format__('#.16g'),v.__format__('+.4g')) | ||
|
||
print_values([ | ||
float('75.5834073120020679681'), | ||
float('75.5834073120020679681e-7'), | ||
float('75.5834073120020679681e-24'), | ||
float('75.5834073120020679681e80'), | ||
float('75.5834073120020679681e300'), | ||
float('75.0'), | ||
float('0.005'), | ||
float('0.0005'), | ||
float('0.5'), | ||
float('0.01'), | ||
float('0.25'), | ||
float('0.25')/2, | ||
float('0.25')/4, | ||
float('0.25')/8, | ||
float('0.25')/16, | ||
float('0.25')/2048, | ||
float('0.25')/4096, | ||
float('10000000253263163212.0'), | ||
(10**60)/1, | ||
float('20000000000000000'), | ||
0.0, | ||
-0.0, | ||
math.inf, | ||
-math.inf, | ||
math.nan, | ||
-math.nan, | ||
float('123.45'), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
75.58340731200207 75.583407 7.558341e+01 75.58340731200207 +75.58 | ||
7.558340731200207e-06 0.000008 7.558341e-06 7.558340731200207e-06 +7.558e-06 | ||
7.558340731200207e-23 0.000000 7.558341e-23 7.558340731200207e-23 +7.558e-23 | ||
7.558340731200207e+81 7558340731200206731762734930317738502291660148265284220384036778702184341124939776.000000 7.558341e+81 7.558340731200207e+81 +7.558e+81 | ||
7.558340731200207e+301 75583407312002066768461022261315172287297487251874586478724757817960934981634094788769653163852924763443651501309652569997165035925379465760402739890567710612092775360309017524288996057690996811122123668937191051711752654751620072621666259734026943606049685516409713620071805443138455356168154210369536.000000 7.558341e+301 7.558340731200207e+301 +7.558e+301 | ||
75 75.000000 7.500000e+01 75.00000000000000 +75 | ||
0.005 0.005000 5.000000e-03 0.005000000000000000 +0.005 | ||
0.0005 0.000500 5.000000e-04 0.0005000000000000000 +0.0005 | ||
0.5 0.500000 5.000000e-01 0.5000000000000000 +0.5 | ||
0.01 0.010000 1.000000e-02 0.01000000000000000 +0.01 | ||
0.25 0.250000 2.500000e-01 0.2500000000000000 +0.25 | ||
0.125 0.125000 1.250000e-01 0.1250000000000000 +0.125 | ||
0.0625 0.062500 6.250000e-02 0.06250000000000000 +0.0625 | ||
0.03125 0.031250 3.125000e-02 0.03125000000000000 +0.03125 | ||
0.015625 0.015625 1.562500e-02 0.01562500000000000 +0.01562 | ||
0.0001220703125 0.000122 1.220703e-04 0.0001220703125000000 +0.0001221 | ||
6.103515625e-05 0.000061 6.103516e-05 6.103515625000000e-05 +6.104e-05 | ||
1.000000025326316e+19 10000000253263163392.000000 1.000000e+19 1.000000025326316e+19 +1e+19 | ||
9.999999999999999e+59 999999999999999949387135297074018866963645011013410073083904.000000 1.000000e+60 9.999999999999999e+59 +1e+60 | ||
2e+16 20000000000000000.000000 2.000000e+16 2.000000000000000e+16 +2e+16 | ||
0 0.000000 0.000000e+00 0.000000000000000 +0 | ||
-0 -0.000000 -0.000000e+00 -0.000000000000000 -0 | ||
inf inf inf inf +inf | ||
-inf -inf -inf -inf -inf | ||
nan nan nan nan +nan | ||
nan nan nan nan +nan | ||
123.45 123.450000 1.234500e+02 123.4500000000000 +123.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
print(float('123431236.632163e-3')) | ||
print(float('123431236.632163e3')) | ||
print(float('123431236.632163e30')) | ||
print(float('123431236.632163e-30')) | ||
print(float('-123431236.632163e-3')) | ||
print(float('-123431236.632163e3')) | ||
print(float('-123431236.632163e30')) | ||
print(float('-123431236.632163e-30')) | ||
print(float('2.1234567')) | ||
print(float('0.1234567')) | ||
print(float('0.001234567')) | ||
print(float('0.00001234567')) | ||
|
||
|
||
print(float('0.000976562500000000325260651745651330202235840260982513427734375')) | ||
print(float('2.47032822920623272088284396434110686182e-324').__format__('.10000g')) | ||
print(float('2.47032822920623272088284396434110686183e-324').__format__('.10000g')) | ||
print(float('4.99e-324').__format__('.10000g')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
123431.236632163 | ||
123431236632.163 | ||
1.23431236632163e+38 | ||
1.23431236632163e-22 | ||
-123431.236632163 | ||
-123431236632.163 | ||
-1.23431236632163e+38 | ||
-1.23431236632163e-22 | ||
2.1234567 | ||
0.1234567 | ||
0.001234567 | ||
1.234567e-05 | ||
0.0009765625000000004 | ||
0 | ||
4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625e-324 | ||
4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625e-324 |