forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.1.19.c
More file actions
63 lines (43 loc) · 991 Bytes
/
task1.1.19.c
File metadata and controls
63 lines (43 loc) · 991 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
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
#include <stdio.h>
#include <float.h> // DBL_EPSILON, DBL_MAX
#include <math.h> //fabs
#include <stdbool.h> // bool type
bool isNearlyZero(double x){
return fabs(x)<0.000001; //2*DBL_EPSILON); // fabs(x) =|x|
}
bool isNearlyEqual(double x, double y){
return (fabs(x-y)<= DBL_EPSILON* 2*(fabs(x) + fabs(y)));
}
double onestep(double x) {
if(x >= 0) return 1;
return 0;
//return (x>=0)?1:0;
}
double onestep_derivative(double x) {
if(isNearlyZero(x)) return DBL_MAX; // x==0
return 0;
}
double ReLu(double x) {
return (x>=0)?x:0;
}
double ReLu_derivative(double x) {
if(isNearlyZero(x)) return 0.5; // x==0
else if(x<0){
return 0;
}
return 1;
}
int main(){
if(isNearlyZero(onestep(-2)-0)){
printf("ok1");
}
if(isNearlyEqual(onestep_derivative(-2),0)){
printf("ok2");
}
if(isNearlyZero(ReLu(-2)-0)){
printf("ok3");
}
if(isNearlyEqual(ReLu_derivative(-2),0)){
printf("ok4");
}
}