This commit is contained in:
Miloslav Ciz 2024-08-31 14:44:45 +02:00
parent 124b9d1e7c
commit 3f374a4713
85 changed files with 2281 additions and 2272 deletions

View file

@ -43,13 +43,13 @@ float
a = 21,
b = 3.0 / 4.0,
c = -10.0 / 3.0;
a = a * b; // multiplication
a += c; // addition
a /= b; // division
a -= 10; // subtraction
a /= 3; // division
printf("%f\n",a);
```
@ -68,7 +68,7 @@ a += c; // addition, no normalization needed
a = (a * UNIT) / b; // division, normalization needed, note the brackets
a -= 10 * UNIT; // subtraction
a /= 3; // division by a number NOT in UNITs, no normalization needed
printf("%d.%d%d%d\n", // writing a nice printing function is left as an exercise :)
a / UNIT,
((a * 10) / UNIT) % 10,
@ -94,7 +94,7 @@ Fixed fixedSqrt(Fixed x)
// stupid brute force square root
int previousError = -1;
for (int test = 0; test <= x; ++test)
{
int error = x - (test * test) / UNIT_FRACTIONS;
@ -124,12 +124,12 @@ int main(void)
for (int i = 0; i <= 10; ++i)
{
printf("%d: ",i);
fixedPrint(fixedSqrt(INT_TO_FIXED(i)));
putchar('\n');
}
return 0;
}
```