diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2023-05-06 15:29:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-06 15:29:22 +0200 |
| commit | f1368f4f812cce360e932a2b337f07aa0f11ef65 (patch) | |
| tree | a377aba55f6542ab83f8f44648fec9a439ed93a5 /exercises/060_floats.zig | |
| parent | 2027c6a403408f07640aa0fa22d6dc7d02da4134 (diff) | |
| parent | e5341b91c107894e585e515731d5ec34fd56c1af (diff) | |
Merge branch 'ratfactor:main' into testing
Diffstat (limited to 'exercises/060_floats.zig')
| -rw-r--r-- | exercises/060_floats.zig | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/exercises/060_floats.zig b/exercises/060_floats.zig index 8ba51db..1320171 100644 --- a/exercises/060_floats.zig +++ b/exercises/060_floats.zig @@ -1,10 +1,11 @@ // // Zig has support for IEEE-754 floating-point numbers in these // specific sizes: f16, f32, f64, f80, and f128. Floating point -// literals may be written in scientific notation: +// literals may be written in the same ways as integers but also +// in scientific notation: // -// const a1: f32 = 1200.0; // 1,200 -// const a2: f32 = 1.2e+3; // 1,200 +// const a1: f32 = 1200; // 1,200 +// const a2: f32 = 1.2e+3; // 1,200 // const b1: f32 = -500_000.0; // -500,000 // const b2: f32 = -5.0e+5; // -500,000 // @@ -22,12 +23,14 @@ // 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 -// operations with numeric literals, ensure the types match. Zig -// does not perform unsafe type coercions behind your back: +// When performing math operations with numeric literals, ensure +// the types match. Zig does not perform unsafe type coercions +// behind your back: // -// var foo: f16 = 13.5 * 5; // ERROR! -// var foo: f16 = 13.5 * 5.0; // No problem, both are floats +// var foo: f16 = 5; // NO ERROR +// +// var foo: u16 = 5; // A literal of a different type +// var bar: f16 = foo; // ERROR // // Please fix the two float problems with this program and // display the result as a whole number. |
