26 lines
776 B
Mojo
26 lines
776 B
Mojo
# probe: Float64 arithmetic and how print writes floats
|
|
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
|
# expect-stdout: -40.0 C is -40.0 F
|
|
# expect-stdout: 0.0 C is 32.0 F
|
|
# expect-stdout: 36.6 C is 97.88000000000001 F
|
|
# expect-stdout: 100.0 C is 212.0 F
|
|
# expect-stdout: 37.0
|
|
# expect-stdout: mean 24.15
|
|
def c_to_f(c: Float64) -> Float64:
|
|
return c * 9.0 / 5.0 + 32.0
|
|
|
|
|
|
def f_to_c(f: Float64) -> Float64:
|
|
return (f - 32.0) * 5.0 / 9.0
|
|
|
|
|
|
def main():
|
|
var readings: List[Float64] = [-40.0, 0.0, 36.6, 100.0]
|
|
for c in readings:
|
|
print(c, "C is", c_to_f(c), "F")
|
|
print(f_to_c(98.6))
|
|
var total = 0.0
|
|
for c in readings:
|
|
total += c
|
|
print("mean", total / 4.0)
|