Skip to content

Commit d973c1b

Browse files
committed
test/string_format_fp30: Variant of string_format for 30-bit stuffed float.
1 parent 50e0a7b commit d973c1b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/float/string_format_fp30.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
def test(fmt, *args):
2+
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
3+
4+
test("{:10.4}", 123.456)
5+
test("{:10.4e}", 123.456)
6+
test("{:10.4e}", -123.456)
7+
#test("{:10.4f}", 123.456)
8+
#test("{:10.4f}", -123.456)
9+
test("{:10.4g}", 123.456)
10+
test("{:10.4g}", -123.456)
11+
test("{:10.4n}", 123.456)
12+
test("{:e}", 100)
13+
test("{:f}", 200)
14+
test("{:g}", 300)
15+
16+
test("{:10.4E}", 123.456)
17+
test("{:10.4E}", -123.456)
18+
#test("{:10.4F}", 123.456)
19+
#test("{:10.4F}", -123.456)
20+
test("{:10.4G}", 123.456)
21+
test("{:10.4G}", -123.456)
22+
23+
test("{:06e}", float("inf"))
24+
test("{:06e}", float("-inf"))
25+
test("{:06e}", float("nan"))
26+
27+
# The following fails right now
28+
#test("{:10.1}", 0.0)
29+
30+
print("%.0f" % (1.750000 % 0.08333333333))
31+
# Below isn't compatible with single-precision float
32+
#print("%.1f" % (1.750000 % 0.08333333333))
33+
#print("%.2f" % (1.750000 % 0.08333333333))
34+
#print("%.12f" % (1.750000 % 0.08333333333))
35+
36+
# tests for errors in format string
37+
38+
try:
39+
'{:10.1b}'.format(0.0)
40+
except ValueError:
41+
print('ValueError')

0 commit comments

Comments
 (0)