|
| 1 | +// Copyright 2012-2015 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(dead_code)] |
| 12 | + |
| 13 | +use intrinsics; |
| 14 | + |
| 15 | +pub mod cmath { |
| 16 | + use libc::{c_float, c_int}; |
| 17 | + |
| 18 | + #[link_name = "m"] |
| 19 | + extern { |
| 20 | + pub fn lgammaf_r(n: c_float, sign: &mut c_int) -> c_float; |
| 21 | + pub fn hypotf(x: c_float, y: c_float) -> c_float; |
| 22 | + pub fn acosf(n: c_float) -> c_float; |
| 23 | + pub fn asinf(n: c_float) -> c_float; |
| 24 | + pub fn atan2f(a: c_float, b: c_float) -> c_float; |
| 25 | + pub fn atanf(n: c_float) -> c_float; |
| 26 | + pub fn coshf(n: c_float) -> c_float; |
| 27 | + pub fn frexpf(n: c_float, value: &mut c_int) -> c_float; |
| 28 | + pub fn ldexpf(x: c_float, n: c_int) -> c_float; |
| 29 | + pub fn sinhf(n: c_float) -> c_float; |
| 30 | + pub fn tanf(n: c_float) -> c_float; |
| 31 | + pub fn tanhf(n: c_float) -> c_float; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +#[inline] |
| 36 | +pub fn floor(x: f32) -> f32 { |
| 37 | + unsafe { intrinsics::floorf32(x) } |
| 38 | +} |
| 39 | + |
| 40 | +#[inline] |
| 41 | +pub fn ceil(x: f32) -> f32 { |
| 42 | + unsafe { intrinsics::ceilf32(x) } |
| 43 | +} |
| 44 | + |
| 45 | +#[inline] |
| 46 | +pub fn powf(x: f32, n: f32) -> f32 { |
| 47 | + unsafe { intrinsics::powf32(x, n) } |
| 48 | +} |
| 49 | + |
| 50 | +#[inline] |
| 51 | +pub fn exp(x: f32) -> f32 { |
| 52 | + unsafe { intrinsics::expf32(x) } |
| 53 | +} |
| 54 | + |
| 55 | +#[inline] |
| 56 | +pub fn ln(x: f32) -> f32 { |
| 57 | + unsafe { intrinsics::logf32(x) } |
| 58 | +} |
| 59 | + |
| 60 | +#[inline] |
| 61 | +pub fn log2(x: f32) -> f32 { |
| 62 | + #[cfg(target_os = "android")] |
| 63 | + return ::sys::android::log2f32(x); |
| 64 | + #[cfg(not(target_os = "android"))] |
| 65 | + return unsafe { intrinsics::log2f32(x) }; |
| 66 | +} |
| 67 | + |
| 68 | +#[inline] |
| 69 | +pub fn log10(x: f32) -> f32 { |
| 70 | + unsafe { intrinsics::log10f32(x) } |
| 71 | +} |
| 72 | + |
| 73 | +#[inline] |
| 74 | +pub fn sin(x: f32) -> f32 { |
| 75 | + unsafe { intrinsics::sinf32(x) } |
| 76 | +} |
| 77 | + |
| 78 | +#[inline] |
| 79 | +pub fn cos(x: f32) -> f32 { |
| 80 | + unsafe { intrinsics::cosf32(x) } |
| 81 | +} |
0 commit comments