issue-2214.rs 1.2 KB
Newer Older
1 2
// xfail-fast

3 4 5 6 7 8 9 10 11 12
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

13 14 15
use core::cast;
use core::libc::{c_double, c_int};
use core::f64::*;
16

17 18 19 20
fn to_c_int(v: &mut int) -> &mut c_int {
    unsafe {
        cast::reinterpret_cast(&v)
    }
21 22
}

23
fn lgamma(n: c_double, value: &mut int) -> c_double {
24 25 26
    unsafe {
        return m::lgamma(n, to_c_int(value));
    }
27 28 29 30
}

#[link_name = "m"]
#[abi = "cdecl"]
31
extern mod m {
32
    #[cfg(unix)]
33
    #[link_name="lgamma_r"] pub fn lgamma(n: c_double, sign: &mut c_int)
34
      -> c_double;
35
    #[cfg(windows)]
36 37
    #[link_name="__lgamma_r"] pub fn lgamma(n: c_double,
                                            sign: &mut c_int) -> c_double;
38

39 40 41 42 43 44
}

fn main() {
  let mut y: int = 5;
  let x: &mut int = &mut y;
  assert (lgamma(1.0 as c_double, x) == 0.0 as c_double);
45
}