This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,32 @@
|
||||
# probe: does Float64(atol(m)) doubled or halved e times give m * 2^e exactly? (yes, for m below 2^53: 0.1, 2^1000, a subnormal, -0.0, an overflow to inf, 1e-16, the double below 1)
|
||||
# stdin: 3602879701896397 -55 1 1000 1 -1074 -0 0 1 1024 -1 1024 2028240960365167 -104 4503599627370495 -52\n
|
||||
# expect-stdout: 0.1
|
||||
# expect-stdout: 1.0715086071862673e+301
|
||||
# expect-stdout: 5e-324
|
||||
# expect-stdout: -0.0
|
||||
# expect-stdout: inf
|
||||
# expect-stdout: -inf
|
||||
# expect-stdout: 1e-16
|
||||
# expect-stdout: 0.9999999999999998
|
||||
def scaled(m: String, e: String) raises -> Float64:
|
||||
var x = Float64(atol(m))
|
||||
if m == "-0":
|
||||
x = -x
|
||||
var k = atol(e)
|
||||
while k > 0:
|
||||
x *= 2.0
|
||||
k -= 1
|
||||
while k < 0:
|
||||
x *= 0.5
|
||||
k += 1
|
||||
return x
|
||||
|
||||
|
||||
def main() raises:
|
||||
var w = List[String]()
|
||||
for s in input().split(" "):
|
||||
w.append(String(s))
|
||||
var i = 0
|
||||
while i + 1 < len(w):
|
||||
print(scaled(w[i], w[i + 1]))
|
||||
i += 2
|
||||
Reference in new issue
Block a user