1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(missing_doc)]
14 //! Bindings for the C math library (for basic mathematic functions)
16 // Function names are almost identical to C's libmath, a few have been
17 // renamed, grep for "rename:"
20 use libc::{c_double, c_int};
24 // Alphabetically sorted by link_name
26 pub fn acos(n: c_double) -> c_double;
27 pub fn asin(n: c_double) -> c_double;
28 pub fn atan(n: c_double) -> c_double;
29 pub fn atan2(a: c_double, b: c_double) -> c_double;
30 pub fn cbrt(n: c_double) -> c_double;
31 pub fn cosh(n: c_double) -> c_double;
32 pub fn erf(n: c_double) -> c_double;
33 pub fn erfc(n: c_double) -> c_double;
34 // rename: for consistency with underscore usage elsewhere
36 pub fn exp_m1(n: c_double) -> c_double;
37 // rename: for clarity and consistency with add/sub/mul/div
39 pub fn abs_sub(a: c_double, b: c_double) -> c_double;
41 pub fn fmax(a: c_double, b: c_double) -> c_double;
43 pub fn fmin(a: c_double, b: c_double) -> c_double;
44 #[link_name="nextafter"]
45 pub fn next_after(x: c_double, y: c_double) -> c_double;
46 pub fn frexp(n: c_double, value: &mut c_int) -> c_double;
47 pub fn hypot(x: c_double, y: c_double) -> c_double;
48 pub fn ldexp(x: c_double, n: c_int) -> c_double;
50 #[link_name="lgamma_r"]
51 pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
53 #[link_name="__lgamma_r"]
54 pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
55 // renamed: "logb" /often/ is confused for log2 by beginners
57 pub fn log_radix(n: c_double) -> c_double;
58 // renamed: to be consitent with log as ln
60 pub fn ln_1p(n: c_double) -> c_double;
62 pub fn ilog_radix(n: c_double) -> c_int;
63 pub fn modf(n: c_double, iptr: &mut c_double) -> c_double;
64 // rename: for consistency with logradix
66 pub fn ldexp_radix(n: c_double, i: c_int) -> c_double;
67 pub fn sinh(n: c_double) -> c_double;
68 pub fn tan(n: c_double) -> c_double;
69 pub fn tanh(n: c_double) -> c_double;
70 pub fn tgamma(n: c_double) -> c_double;
72 // These are commonly only available for doubles
74 pub fn j0(n: c_double) -> c_double;
75 pub fn j1(n: c_double) -> c_double;
76 pub fn jn(i: c_int, n: c_double) -> c_double;
78 pub fn y0(n: c_double) -> c_double;
79 pub fn y1(n: c_double) -> c_double;
80 pub fn yn(i: c_int, n: c_double) -> c_double;
85 use libc::{c_float, c_int};
89 // Alphabetically sorted by link_name
92 pub fn acos(n: c_float) -> c_float;
94 pub fn asin(n: c_float) -> c_float;
96 pub fn atan(n: c_float) -> c_float;
98 pub fn atan2(a: c_float, b: c_float) -> c_float;
100 pub fn cbrt(n: c_float) -> c_float;
102 pub fn cosh(n: c_float) -> c_float;
104 pub fn erf(n: c_float) -> c_float;
106 pub fn erfc(n: c_float) -> c_float;
107 #[link_name="expm1f"]
108 pub fn exp_m1(n: c_float) -> c_float;
110 pub fn abs_sub(a: c_float, b: c_float) -> c_float;
111 #[link_name="frexpf"]
112 pub fn frexp(n: c_float, value: &mut c_int) -> c_float;
114 pub fn fmax(a: c_float, b: c_float) -> c_float;
116 pub fn fmin(a: c_float, b: c_float) -> c_float;
117 #[link_name="nextafterf"]
118 pub fn next_after(x: c_float, y: c_float) -> c_float;
119 #[link_name="hypotf"]
120 pub fn hypot(x: c_float, y: c_float) -> c_float;
121 #[link_name="ldexpf"]
122 pub fn ldexp(x: c_float, n: c_int) -> c_float;
125 #[link_name="lgammaf_r"]
126 pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
129 #[link_name="__lgammaf_r"]
130 pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
133 pub fn log_radix(n: c_float) -> c_float;
134 #[link_name="log1pf"]
135 pub fn ln_1p(n: c_float) -> c_float;
136 #[link_name="ilogbf"]
137 pub fn ilog_radix(n: c_float) -> c_int;
139 pub fn modf(n: c_float, iptr: &mut c_float) -> c_float;
140 #[link_name="scalbnf"]
141 pub fn ldexp_radix(n: c_float, i: c_int) -> c_float;
143 pub fn sinh(n: c_float) -> c_float;
145 pub fn tan(n: c_float) -> c_float;
147 pub fn tanh(n: c_float) -> c_float;
148 #[link_name="tgammaf"]
149 pub fn tgamma(n: c_float) -> c_float;