-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGradualChange.c
More file actions
35 lines (27 loc) · 823 Bytes
/
TestGradualChange.c
File metadata and controls
35 lines (27 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
/*
Experiment to check if particular algorithms relating to
floating-point maths would yield a gradually-changing shape.
One failed algorithm, one which is a success.
*/
int main()
{
double GraduallyChangingShape, TheSight;
GraduallyChangingShape = -105;
TheSight=10000;
while (1)
{
/* Wrong; Shape Remains Frozen */
/*
GraduallyChangingShape = TheSight / 2;
*/
/*Correct: The simulated shape changes gradually by fading into the correct
number.
*/
GraduallyChangingShape = (GraduallyChangingShape + TheSight) / 2;
printf("%f \n", GraduallyChangingShape);
/* Making sure we're able to see the variable at idividual points in time. */
getchar();
}
return 0;
}