diff options
author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2024-02-28 12:06:56 +0000 |
---|---|---|
committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2024-02-28 12:06:56 +0000 |
commit | 277304454a8f18b65985d61cc62c01d00b9dc2d0 (patch) | |
tree | f9fb069a50ce85a248302c9aee6d7989f4d52543 /exercises/094_c_math.zig | |
parent | 48b203202423090bb1714e61b85a4f598fc4e071 (diff) | |
parent | 9e48c9a339cde73fb7477f252e98efe0fc6d8de0 (diff) |
Merge pull request 'Added notes to exercise 94 c_math.' (#53) from 094_c-math into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/53
Diffstat (limited to 'exercises/094_c_math.zig')
-rw-r--r-- | exercises/094_c_math.zig | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/exercises/094_c_math.zig b/exercises/094_c_math.zig index e650f6e..61e2c7b 100644 --- a/exercises/094_c_math.zig +++ b/exercises/094_c_math.zig @@ -1,19 +1,26 @@ // // Often, C functions are used where no equivalent Zig function exists -// yet. Since the integration of a C function is very simple, as already +// yet. Okay, that's getting less and less. ;-) +// +// Since the integration of a C function is very simple, as already // seen in the last exercise, it naturally offers itself to use the // very large variety of C functions for our own programs. // As an example: // // Let's say we have a given angle of 765.2 degrees. If we want to // normalize that, it means that we have to subtract X * 360 degrees -// to get the correct angle. How could we do that? A good method is -// to use the modulo function. But if we write "765.2 % 360", it won't -// work, because the standard modulo function works only with integer -// values. In the C library "math", there is a function called "fmod"; -// the "f" stands for floating and means that we can solve modulo for -// real numbers. With this function, it should be possible to normalize -// our angle. Let's go. +// to get the correct angle. +// How could we do that? A good method is to use the modulo function. +// But if we write "765.2 % 360", it only works with float values +// that are known at compile time. +// In Zig, we would use %mod(a, b) instead. +// +// Let us now assume that we cannot do this in Zig, but only with +// a C function from the standard library. In the library "math", +// there is a function called "fmod"; the "f" stands for floating +// and means that we can solve modulo for real numbers. With this +// function, it should be possible to normalize our angle. +// Let's go. const std = @import("std"); |