1
0
Fork 0
mirror of https://github.com/ratfactor/ziglings synced 2024-05-18 10:46:05 +02:00

Exercise 094: Correct spelling and grammar

This commit is contained in:
Zolo Zithro 2023-03-30 09:40:13 -04:00
parent 53597efcf3
commit b2c0c5d85e

View File

@ -1,19 +1,19 @@
// //
// Often C functions are used where no equivalent Zig function exists // 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. Since the integration of a C function is very simple, as already
// seen in the last exercise, it naturally offers itself to use the // seen in the last exercise, it naturally offers itself to use the
// very large variety of C functions for the own programs. // very large variety of C functions for our own programs.
// In addition immediately an example: // As an example:
// //
// Let's say we have a given angle of 765.2 degrees. If we want to // 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 // 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 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 // 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 // work, because the standard modulo function works only with integer
// values. In the C library "math" there is a function called "fmod". // 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 // the "f" stands for floating and means that we can solve modulo for
// real numbers. With this function it should be possible to normalize // real numbers. With this function, it should be possible to normalize
// our angel. Let's go. // our angle. Let's go.
const std = @import("std"); const std = @import("std");
@ -23,12 +23,12 @@ const c = @cImport({
}); });
pub fn main() !void { pub fn main() !void {
const angel = 765.2; const angle = 765.2;
const circle = 360; const circle = 360;
// Here we call the C function 'fmod' to get our normalized angel. // Here we call the C function 'fmod' to get our normalized angle.
const result = c.fmod(angel, circle); const result = c.fmod(angle, circle);
// We use formatters for the desired precision and to truncate the decimal places // We use formatters for the desired precision and to truncate the decimal places
std.debug.print("The normalized angle of {d: >3.1} degrees is {d: >3.1} degrees.\n", .{ angel, result }); std.debug.print("The normalized angle of {d: >3.1} degrees is {d: >3.1} degrees.\n", .{ angle, result });
} }