|
Revision 2093, 0.6 KB
(checked in by Chuck.Esterbrook, 3 years ago)
|
|
Minimal support for ** operator (power expressions).
credit:hopscc
ticket:114
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | class ToThePower |
|---|
| 2 | |
|---|
| 3 | def main |
|---|
| 4 | for i, answer in [[2, 100], [3, 1_000], [4, 10_000], [5, 100_000]] |
|---|
| 5 | x = 10 ** i |
|---|
| 6 | assert x inherits int # .warning. The expression is always of type "int" |
|---|
| 7 | assert x == answer |
|---|
| 8 | |
|---|
| 9 | for i, answer in [[2, 4], [3, 8], [4, 16], [5, 32]] |
|---|
| 10 | y = 2 ** i |
|---|
| 11 | assert y inherits int # .warning. The expression is always of type "int" |
|---|
| 12 | assert y == answer |
|---|
| 13 | |
|---|
| 14 | for j, answerf in [[2f, 9f], [3f, 27f], [4f, 81f], [5f, 243f]] |
|---|
| 15 | z = 3 ** j |
|---|
| 16 | assert z inherits float # .warning. The expression is always of type "float" |
|---|
| 17 | assert z == answerf |
|---|
| 18 | |
|---|
| 19 | f = 1.1f ** 3f # 1.331 |
|---|
| 20 | assert f >= 1.331f and f < 1.3311f |
|---|