]> git.lizzy.rs Git - rust.git/blob - src/libstd/num/cmath.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / libstd / num / cmath.rs
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.
4 //
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.
10
11 #![allow(missing_doc)]
12 #![allow(dead_code)]
13
14 //! Bindings for the C math library (for basic mathematic functions)
15
16 // Function names are almost identical to C's libmath, a few have been
17 // renamed, grep for "rename:"
18
19 pub mod c_double {
20     use libc::{c_double, c_int};
21
22     #[link_name = "m"]
23     extern {
24         // Alphabetically sorted by link_name
25
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
35         #[link_name="expm1"]
36         pub fn exp_m1(n: c_double) -> c_double;
37         // rename: for clarity and consistency with add/sub/mul/div
38         #[link_name="fdim"]
39         pub fn abs_sub(a: c_double, b: c_double) -> c_double;
40         #[link_name="fmax"]
41         pub fn fmax(a: c_double, b: c_double) -> c_double;
42         #[link_name="fmin"]
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;
49         #[cfg(unix)]
50         #[link_name="lgamma_r"]
51         pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
52         #[cfg(windows)]
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
56         #[link_name="logb"]
57         pub fn log_radix(n: c_double) -> c_double;
58         // renamed: to be consitent with log as ln
59         #[link_name="log1p"]
60         pub fn ln_1p(n: c_double) -> c_double;
61         #[link_name="ilogb"]
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
65         #[link_name="scalbn"]
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;
71
72         // These are commonly only available for doubles
73
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;
77
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;
81     }
82 }
83
84 pub mod c_float {
85     use libc::{c_float, c_int};
86
87     #[link_name = "m"]
88     extern {
89         // Alphabetically sorted by link_name
90
91         #[link_name="acosf"]
92         pub fn acos(n: c_float) -> c_float;
93         #[link_name="asinf"]
94         pub fn asin(n: c_float) -> c_float;
95         #[link_name="atanf"]
96         pub fn atan(n: c_float) -> c_float;
97         #[link_name="atan2f"]
98         pub fn atan2(a: c_float, b: c_float) -> c_float;
99         #[link_name="cbrtf"]
100         pub fn cbrt(n: c_float) -> c_float;
101         #[link_name="coshf"]
102         pub fn cosh(n: c_float) -> c_float;
103         #[link_name="erff"]
104         pub fn erf(n: c_float) -> c_float;
105         #[link_name="erfcf"]
106         pub fn erfc(n: c_float) -> c_float;
107         #[link_name="expm1f"]
108         pub fn exp_m1(n: c_float) -> c_float;
109         #[link_name="fdimf"]
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;
113         #[link_name="fmaxf"]
114         pub fn fmax(a: c_float, b: c_float) -> c_float;
115         #[link_name="fminf"]
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;
123
124         #[cfg(unix)]
125         #[link_name="lgammaf_r"]
126         pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
127
128         #[cfg(windows)]
129         #[link_name="__lgammaf_r"]
130         pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
131
132         #[link_name="logbf"]
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;
138         #[link_name="modff"]
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;
142         #[link_name="sinhf"]
143         pub fn sinh(n: c_float) -> c_float;
144         #[link_name="tanf"]
145         pub fn tan(n: c_float) -> c_float;
146         #[link_name="tanhf"]
147         pub fn tanh(n: c_float) -> c_float;
148         #[link_name="tgammaf"]
149         pub fn tgamma(n: c_float) -> c_float;
150     }
151 }