Merge pull request 'Changed exercise 60 to require change of format' (#384) from markuxcu/exercises:fix-060 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/384
This commit is contained in:
Chris Boesch
2026-04-07 09:25:59 +02:00
3 changed files with 15 additions and 4 deletions

View File

@@ -1010,7 +1010,7 @@ const exercises = [_]Exercise{
}, },
.{ .{
.main_file = "060_floats.zig", .main_file = "060_floats.zig",
.output = "Shuttle liftoff weight: 2032 metric tons", .output = "Shuttle liftoff weight: 2.032e3 metric tons",
}, },
.{ .{
.main_file = "061_coercions.zig", .main_file = "061_coercions.zig",

View File

@@ -49,6 +49,8 @@ pub fn main() void {
// notation. Experiment with '{d}' and '{d:.3}' to see how // notation. Experiment with '{d}' and '{d:.3}' to see how
// decimal formatting works, or try '{e}' and '{e:.3}' for // decimal formatting works, or try '{e}' and '{e:.3}' for
// scientific notation. // scientific notation.
// NOTE: The weight of the shuttle is a huge number, a scientific notation
// may be more appropriate.
print("Shuttle liftoff weight: {d:.0} metric tons\n", .{shuttle_weight / 1e3}); print("Shuttle liftoff weight: {d:.0} metric tons\n", .{shuttle_weight / 1e3});
} }

View File

@@ -1,11 +1,20 @@
--- exercises/060_floats.zig 2025-10-17 17:58:44.811502880 +0200 --- exercises/060_floats.zig 2026-04-03 14:40:17.582344768 +0200
+++ answers/060_floats.zig 2025-10-17 17:57:39.227157388 +0200 +++ answers/060_floats.zig 2026-04-03 14:49:26.997886326 +0200
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
// //
// We'll convert this weight from pounds to metric units at a // We'll convert this weight from pounds to metric units at a
// conversion of 0.453592 kg to the pound. // conversion of 0.453592 kg to the pound.
- const shuttle_weight: f16 = 0.453592 * 4480e3; - const shuttle_weight: f16 = 0.453592 * 4480e3;
+ const shuttle_weight: f32 = 0.453592 * 4.480e6; + const shuttle_weight: f32 = 0.453592 * 4480e3;
// By default, float values are formatted in standard decimal // By default, float values are formatted in standard decimal
// notation. Experiment with '{d}' and '{d:.3}' to see how // notation. Experiment with '{d}' and '{d:.3}' to see how
@@ -51,7 +51,7 @@
// scientific notation.
// NOTE: The weight of the shuttle is a huge number, a scientific notation
// may be more appropriate.
- print("Shuttle liftoff weight: {d:.0} metric tons\n", .{shuttle_weight / 1e3});
+ print("Shuttle liftoff weight: {e:.3} metric tons\n", .{shuttle_weight / 1e3});
}
// Floating further: