The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file math.h
5 * @brief floating-point functions (double, and float with an f).
6 *
7 * the functions use the x87 FPU instructions, which exist on i686 and on
8 * x86_64. the results are as exact as those instructions give; errno is
9 * not set.
10 */
11
12// the constants of POSIX (XSI)
13#define M_E 2.7182818284590452354 // e
14#define M_LOG2E 1.4426950408889634074 // log2(e)
15#define M_LOG10E 0.43429448190325182765 // log10(e)
16#define M_LN2 0.69314718055994530942 // ln(2)
17#define M_LN10 2.30258509299404568402 // ln(10)
18#define M_PI 3.14159265358979323846 // pi
19#define M_PI_2 1.57079632679489661923 // pi/2
20#define M_PI_4 0.78539816339744830962 // pi/4
21#define M_1_PI 0.31830988618379067154 // 1/pi
22#define M_2_PI 0.63661977236758134308 // 2/pi
23#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
24#define M_SQRT2 1.41421356237309504880 // sqrt(2)
25#define M_SQRT1_2 0.70710678118654752440 // 1/sqrt(2)
26#define HUGE_VAL (__builtin_huge_val())
27#define INFINITY (__builtin_inff())
28#define NAN (__builtin_nanf(""))
29
30#define HUGE_VALF (__builtin_huge_valf())
31#define HUGE_VALL (__builtin_huge_vall())
32
33#define isnan(x) __builtin_isnan(x)
34#define isinf(x) __builtin_isinf(x)
35#define isfinite(x) __builtin_isfinite(x)
36#define signbit(x) __builtin_signbit(x)
37
38double fabs(double x);
39/** the smaller (larger) of two; a NaN gives the other one */
40double fmin(double a, double b);
41double fmax(double a, double b);
42double floor(double x);
43double ceil(double x);
44double round(double x);
45double trunc(double x);
46double fmod(double x, double y);
47double sqrt(double x);
48double sin(double x);
49double cos(double x);
50double tan(double x);
51double atan(double x);
52double atan2(double y, double x);
53double asin(double x);
54double acos(double x);
55double exp(double x);
56double log(double x);
57double log2(double x);
58double log10(double x);
59double pow(double x, double y);
60
61/** x * 2^exponent */
62double ldexp(double x, int exponent);
63double scalbn(double x, int exponent);
64
65/**
66 * split x into a fraction in [0.5, 1) (or 0) and a power of 2:
67 * x = fraction * 2^*exponent.
68 */
69double frexp(double x, int *exponent);
70
71// long double (the x87's 80-bit numbers)
72long double fabsl(long double x);
73long double fmodl(long double x, long double y);
74long double frexpl(long double x, int *exponent);
75long double ldexpl(long double x, int exponent);
76long double scalbnl(long double x, int exponent);
77/** x with the sign of y */
78long double copysignl(long double x, long double y);
79double copysign(double x, double y);
80
81double sinh(double x);
82double cosh(double x);
83double tanh(double x);
84
85// the float functions: each is its double function, rounded to float
86// once. sqrtf is so exact; the others are within one unit in the last
87// place of the exact result.
88float fabsf(float x);
89float floorf(float x);
90float ceilf(float x);
91float roundf(float x);
92float truncf(float x);
93float sqrtf(float x);
94float sinf(float x);
95float cosf(float x);
96float tanf(float x);
97float atanf(float x);
98float asinf(float x);
99float acosf(float x);
100float expf(float x);
101float logf(float x);
102float log2f(float x);
103float log10f(float x);
104float sinhf(float x);
105float coshf(float x);
106float tanhf(float x);
107float fminf(float a, float b);
108float fmaxf(float a, float b);
109float fmodf(float a, float b);
110float atan2f(float a, float b);
111float powf(float a, float b);
112float copysignf(float a, float b);
113float ldexpf(float x, int exp);
114float scalbnf(float x, int n);
115float frexpf(float x, int *exp);
double frexp(double x, int *exponent)
split x into a fraction in [0.5, 1) (or 0) and a power of 2: x = fraction * 2^*exponent.
float floorf(float x)
float expf(float x)
float frexpf(float x, int *exp)
float fmodf(float a, float b)
double fmin(double a, double b)
the smaller (larger) of two; a NaN gives the other one
float sinhf(float x)
double atan(double x)
double ceil(double x)
long double frexpl(long double x, int *exponent)
float fmaxf(float a, float b)
double atan2(double y, double x)
float scalbnf(float x, int n)
double cosh(double x)
double log2(double x)
long double fabsl(long double x)
double fmax(double a, double b)
float sqrtf(float x)
float coshf(float x)
double fmod(double x, double y)
float fminf(float a, float b)
double cos(double x)
double log10(double x)
float tanf(float x)
float atan2f(float a, float b)
double floor(double x)
float asinf(float x)
float tanhf(float x)
float log2f(float x)
float cosf(float x)
double round(double x)
float logf(float x)
double trunc(double x)
double sinh(double x)
float sinf(float x)
float ceilf(float x)
long double scalbnl(long double x, int exponent)
double fabs(double x)
long double ldexpl(long double x, int exponent)
float acosf(float x)
float fabsf(float x)
double tan(double x)
double pow(double x, double y)
float atanf(float x)
float copysignf(float a, float b)
float truncf(float x)
float powf(float a, float b)
long double fmodl(long double x, long double y)
double asin(double x)
float ldexpf(float x, int exp)
double sin(double x)
double scalbn(double x, int exponent)
double sqrt(double x)
double ldexp(double x, int exponent)
x * 2^exponent
double copysign(double x, double y)
double log(double x)
float roundf(float x)
double exp(double x)
float log10f(float x)
long double copysignl(long double x, long double y)
x with the sign of y
double acos(double x)
double tanh(double x)