-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlikimvrt.c
67 lines (56 loc) · 1.06 KB
/
likimvrt.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include <math.h>
#include "likimvrt.h"
/*
likimvrt.c
math.h for fabs() : absolute val. function
*/
static double tol = 0.000001;
/*
int main(void) {
double d = 3*0.1;
if(d == 0.3)
{
printf("Arvo d = %.20f on %.20f\n", d, 0.3);
}
else
{
printf("Arvo d = %.20f ei ole %.20f\n", d, 0.3);
}
printf("Toleranssi: %.20f\n", lueToleranssi());
if(doubleVrt(d, 0.3))
{
printf("Arvo d = %.20f on likimäärin %.20f\n", d, 0.3);
}
else
{
printf("Arvo d = %.20f ei ole likimäärin %.20f\n", d, 0.3);
}
asetaToleranssi(0.0000000000000000001);
printf("Uusi toleranssi: %.20f\n", lueToleranssi());
if(doubleVrt(d, 0.3))
{
printf("Arvo d = %.20f on likimäärin %.20f\n", d, 0.3);
}
else
{
printf("Arvo d = %.20f ei ole likimäärin %.20f\n", d, 0.3);
}
return 0;
}
*/
double lueToleranssi() {
return tol;
}
void asetaToleranssi(double t) {
tol = t;
}
/* returns 0/1 */
int doubleVrt(double a, double b) {
/* smaller or equal than */
if(fabs(a-b) <= tol) {
return 1;
} else {
return 0;
}
}