-
Notifications
You must be signed in to change notification settings - Fork 1
/
math.c
101 lines (76 loc) · 1.41 KB
/
math.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*--------------------------------------------------------------------------
** file: MATH.C
** project: hoc3, "Higher Order Calculator"
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include "hocdecl.h"
double errcheck() ;
double Log( double x)
{
return errcheck( log(x), "log") ;
}
double Log10( double x)
{
return errcheck( log10(x), "log10") ;
}
double Exp( double x)
{
return errcheck( exp(x), "exp") ;
}
double Pow( double x, double y)
{
return errcheck( pow(x, y), "exponentiation") ;
}
double integer( double x)
{
return (double)(long) x ;
}
double Sqrt( double x)
{
return errcheck( sqrt(x), "sqrt") ;
}
double errcheck( double d, char *s)
{
if (errno == EDOM) {
errno = 0 ;
execerror( s, "argument out of domain") ;
}
else if (errno == ERANGE) {
errno = 0 ;
execerror(s, "result out of range") ;
}
return d ;
}
double ret_val = 0.0;
double f2c(double d)
{
ret_val = (5 * (d-32)) / 9;
return ret_val;
}
double c2f(double d)
{
ret_val = (d * 9)/5 + 32;
return ret_val;
}
double in2mm(double d)
{
ret_val = (d * 25.4);
return ret_val;
}
double mm2in(double d)
{
ret_val = (d / 25.4);
return ret_val;
}
double po2kg(double d)
{
ret_val = ((d * 453.592) / 1000);
return ret_val;
}
double kg2po(double d)
{
ret_val = ((d * 1000) / 453.592);
return ret_val;
}