1 /* LibTomFloat, multiple-precision floating-point library
3 * LibTomFloat is a library that provides multiple-precision
4 * floating-point artihmetic as well as trigonometric functionality.
6 * This library requires the public domain LibTomMath to be installed.
8 * This library is free for all purposes without any express
11 * Tom St Denis, tomstdenis@iahu.ca, http://float.libtomcrypt.org
18 /* this is mp_float type */
21 long radix
, /* how many bits for mantissa */
22 exp
; /* current exponent, e.g. mantissa * 2^exp == number */
26 int mpf_init(mp_float
*a
, long radix
);
27 void mpf_clear(mp_float
*a
);
29 int mpf_init_multi(long radix
, mp_float
*a
, ...);
30 void mpf_clear_multi(mp_float
*a
, ...);
32 int mpf_init_copy(mp_float
*a
, mp_float
*b
);
34 int mpf_copy(mp_float
*src
, mp_float
*dest
);
35 void mpf_exch(mp_float
*a
, mp_float
*b
);
38 int mpf_normalize(mp_float
*a
);
39 int mpf_normalize_to(mp_float
*a
, long radix
);
40 int mpf_iterations(mp_float
*a
);
43 int mpf_const_0(mp_float
*a
); /* valid zero */
44 int mpf_const_d(mp_float
*a
, long d
); /* valid d */
45 int mpf_const_ln_d(mp_float
*a
, long b
); /* a = ln(b) */
46 int mpf_const_sqrt_d(mp_float
*a
, long b
); /* a = sqrt(b); */
48 /* math constants as they appear in math.h */
49 int mpf_const_e(mp_float
*a
); /* e */
50 int mpf_const_l2e(mp_float
*a
); /* log_2 e */
51 int mpf_const_l10e(mp_float
*a
); /* log_10 e */
52 int mpf_const_le2(mp_float
*a
); /* log_e 2 */
53 int mpf_const_pi(mp_float
*a
); /* Pi */
54 int mpf_const_pi2(mp_float
*a
); /* Pi/2 */
55 int mpf_const_pi4(mp_float
*a
); /* Pi/4 */
56 int mpf_const_1pi(mp_float
*a
); /* 1/Pi */
57 int mpf_const_2pi(mp_float
*a
); /* 2/Pi */
58 int mpf_const_2rpi(mp_float
*a
); /* 2/sqrt(Pi) */
59 int mpf_const_r2(mp_float
*a
); /* sqrt(2) */
60 int mpf_const_1r2(mp_float
*a
); /* 1/sqrt(2) */
63 int mpf_abs(mp_float
*a
, mp_float
*b
); /* absolute */
64 int mpf_neg(mp_float
*a
, mp_float
*b
); /* negation */
67 int mpf_mul_2(mp_float
*a
, mp_float
*b
); /* b = 2a */
68 int mpf_div_2(mp_float
*a
, mp_float
*b
); /* b = a/2 */
69 int mpf_add(mp_float
*a
, mp_float
*b
, mp_float
*c
); /* c = a + b */
70 int mpf_sub(mp_float
*a
, mp_float
*b
, mp_float
*c
); /* c = a - b */
71 int mpf_mul(mp_float
*a
, mp_float
*b
, mp_float
*c
); /* c = a * b */
72 int mpf_div(mp_float
*a
, mp_float
*b
, mp_float
*c
); /* c = a / b */
73 int mpf_sqr(mp_float
*a
, mp_float
*b
); /* b = a^2 */
75 int mpf_add_d(mp_float
*a
, long b
, mp_float
*c
); /* c = a + b */
76 int mpf_sub_d(mp_float
*a
, long b
, mp_float
*c
); /* c = a - b */
77 int mpf_mul_d(mp_float
*a
, long b
, mp_float
*c
); /* c = a * b */
78 int mpf_div_d(mp_float
*a
, long b
, mp_float
*c
); /* c = a / b */
81 int mpf_cmp(mp_float
*a
, mp_float
*b
);
82 int mpf_cmp_d(mp_float
*a
, long b
, int *res
);
83 #define mpf_iszero(a) mp_iszero(&((a)->mantissa))
86 int mpf_exp(mp_float
*a
, mp_float
*b
); /* b = e^a */
87 int mpf_pow(mp_float
*a
, mp_float
*b
, mp_float
*c
); /* c = a^b */
88 int mpf_ln(mp_float
*a
, mp_float
*b
); /* b = ln a */
89 int mpf_invsqrt(mp_float
*a
, mp_float
*b
); /* b = 1/sqrt(a) */
90 int mpf_inv(mp_float
*a
, mp_float
*b
); /* b = 1/a */
91 int mpf_sqrt(mp_float
*a
, mp_float
*b
); /* b = sqrt(a) */
94 int mpf_cos(mp_float
*a
, mp_float
*b
); /* b = cos(a) */
95 int mpf_sin(mp_float
*a
, mp_float
*b
); /* b = sin(a) */
96 int mpf_tan(mp_float
*a
, mp_float
*b
); /* b = tan(a) */
97 int mpf_acos(mp_float
*a
, mp_float
*b
); /* b = acos(a) */
98 int mpf_asin(mp_float
*a
, mp_float
*b
); /* b = asin(a) */
99 int mpf_atan(mp_float
*a
, mp_float
*b
); /* b = atan(a) */
101 /* ASCII <=> mp_float conversions */
102 char *mpf_to_string(mp_float
*a
, mp_digit radix
);
103 int mpf_from_string(mp_float
*a
, const char *str
, mp_digit radix
);