-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
math.c
89 lines (73 loc) · 1.45 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
/*--------------------------------------------------------------------------
** file: MATH.C
** project: hoc3, "Higher Order Calculator"
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include "hocdecl.h"
static long double errcheck(long double d, const 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;
}
long double Log(long double x)
{
return errcheck(logl(x), "log");
}
long double Log10(long double x)
{
return errcheck(log10l(x), "log10");
}
long double Exp(long double x)
{
return errcheck(expl(x), "exp");
}
long double Pow(long double x, long double y)
{
return errcheck(powl(x, y), "exponentiation");
}
long double integer(long double x)
{
return (long double)(long long)x;
}
long double Sqrt(long double x)
{
return errcheck(sqrtl(x), "sqrt");
}
/* Fahrenheit to Celsius */
long double f2c(long double d)
{
return (5 * (d - 32)) / 9;
}
/* Celsius to Fahrenheit */
long double c2f(long double d)
{
return (d * 9) / 5 + 32;
}
/* Inches to millimeter */
long double in2mm(long double d)
{
return d * 25.4;
}
/* Millimeter to inches */
long double mm2in(long double d)
{
return d / 25.4;
}
/* Pounds to kilograms */
long double po2kg(long double d)
{
return (d * 453.592) / 1000;
}
/* Kilograms to pounds */
long double kg2po(long double d)
{
return (d * 1000) / 453.592;
}