diff options
author | Arya-Elfren <109028294+Arya-Elfren@users.noreply.github.com> | 2023-04-28 11:32:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 11:32:45 +0100 |
commit | 599bea57051efcfaa7a81cb2a846fe095b9759c0 (patch) | |
tree | 6841eabb8f6f0ed05bb7de4c7d0edbbb3118197e /exercises/060_floats.zig | |
parent | 116546a996a12a2e68a68ddf7926d2b4e708c52c (diff) |
Simplify `f16` coersion example
Diffstat (limited to 'exercises/060_floats.zig')
-rw-r--r-- | exercises/060_floats.zig | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/exercises/060_floats.zig b/exercises/060_floats.zig index 0ebd7a2..a04a54d 100644 --- a/exercises/060_floats.zig +++ b/exercises/060_floats.zig @@ -23,15 +23,12 @@ // const pi: f16 = 3.1415926535; // rounds to 3.140625 // const av: f16 = 6.02214076e+23; // Avogadro's inf(inity)! // -// A float literal has a decimal point. When performing math +// A float literal doesn't need a decimal point. When performing math // operations with numeric literals, ensure the types match. Zig // does not perform unsafe type coercions behind your back: // -// fn foo(bar: u16) f16 { return 13.5 * bar; } // ERROR! -// var foo: f16 = 13.5 * @as(u8, 5); // ERROR! -// var foo: f16 = 13.5 * 5; // This is a safe compile-time -// // conversion, so no problem! -// var foo: f16 = 13.5 * 5.0; // No problem, both are floats +// var foo: f16 = 5; // NO ERROR +// var foo: f16 = @as(u16, 5); // ERROR // // Please fix the two float problems with this program and // display the result as a whole number. |