issue-2214.rs 1.2 KB
Newer Older
1
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// 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.

11

12 13
#![feature(libc)]

14 15
extern crate libc;

A
Alex Crichton 已提交
16
use std::mem;
17
use libc::{c_double, c_int};
18

19
fn to_c_int(v: &mut isize) -> &mut c_int {
20
    unsafe {
A
Alex Crichton 已提交
21
        mem::transmute_copy(&v)
22
    }
23 24
}

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

31
mod m {
32
    use libc::{c_double, c_int};
33

34
    #[link_name = "m"]
S
Steve Klabnik 已提交
35
    extern {
36 37 38 39 40 41 42
        #[cfg(unix)]
        #[link_name="lgamma_r"]
        pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
        #[cfg(windows)]
        #[link_name="__lgamma_r"]
        pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
    }
43 44
}

45
pub fn main() {
46 47
  let mut y: isize = 5;
  let x: &mut isize = &mut y;
48
  assert_eq!(lgamma(1.0 as c_double, x), 0.0 as c_double);
49
}