my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'adjusted comment to zig 0.16' (#422) from i421 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/422

Chris Boesch (May 2, 2026, 11:08 PM +0200) 1ba1e301 6048e6ef

+15 -8
+10 -3
exercises/060_floats.zig
··· 27 27 // the types match. Zig does not perform unsafe type coercions 28 28 // behind your back: 29 29 // 30 - // var foo: f16 = 5; // NO ERROR 30 + // var foo: f16 = 5; // NO ERROR 31 31 // 32 - // var foo: u16 = 5; // A literal of a different type 33 - // var bar: f16 = foo; // ERROR 32 + // A runtime value can coerce to a different type, 33 + // as long as the value is losslessly representable: 34 + // 35 + // var foo: u16 = 5; 36 + // var bar: f16 = foo; // NO ERROR (5 fits in f16) 37 + // 38 + // var foo: u16 = 49876; 39 + // var bar: f16 = foo; // ERROR (49876 not representable in f16) 40 + // 34 41 // 35 42 // Please fix the two float problems with this program and 36 43 // display the result as a whole number.
+5 -5
patches/patches/060_floats.patch
··· 1 - --- exercises/060_floats.zig 2026-04-03 14:40:17.582344768 +0200 2 - +++ answers/060_floats.zig 2026-04-03 14:49:26.997886326 +0200 3 - @@ -43,7 +43,7 @@ 1 + --- exercises/060_floats.zig 2026-05-02 19:22:46.225370223 +0200 2 + +++ answers/060_floats.zig 2026-05-02 19:22:47.523142218 +0200 3 + @@ -50,7 +50,7 @@ 4 4 // 5 5 // We'll convert this weight from pounds to metric units at a 6 6 // conversion of 0.453592 kg to the pound. ··· 9 9 10 10 // By default, float values are formatted in standard decimal 11 11 // notation. Experiment with '{d}' and '{d:.3}' to see how 12 - @@ -51,7 +51,7 @@ 12 + @@ -58,7 +58,7 @@ 13 13 // scientific notation. 14 14 // NOTE: The weight of the shuttle is a huge number, a scientific notation 15 15 // may be more appropriate. 16 16 - print("Shuttle liftoff weight: {d:.0} metric tons\n", .{shuttle_weight / 1e3}); 17 17 + print("Shuttle liftoff weight: {e:.3} metric tons\n", .{shuttle_weight / 1e3}); 18 18 } 19 - 19 + 20 20 // Floating further: