Trying to remove wrappers from float

This commit is contained in:
Stefan Plantikow 2011-12-22 15:19:43 +01:00
parent c314a9cad1
commit 49d36c7f85
7 changed files with 349 additions and 111 deletions

View File

@ -1,117 +1,119 @@
import ctypes::c_int;
import ctypes::c_float;
import ctypes::c_double;
// FIXME scalbn copysign
#[link_name = "m"]
#[abi = "cdecl"]
native mod f64 {
native mod c_double {
// Alpabetically sorted by link_name
pure fn acos(n: f64) -> f64;
pure fn asin(n: f64) -> f64;
pure fn atan(n: f64) -> f64;
pure fn atan2(a: f64, b: f64) -> f64;
pure fn cbrt(n: f64) -> f64;
pure fn ceil(n: f64) -> f64;
pure fn cos(n: f64) -> f64;
pure fn cosh(n: f64) -> f64;
pure fn erf(n: f64) -> f64;
pure fn erfc(n: f64) -> f64;
pure fn exp(n: f64) -> f64;
pure fn expm1(n: f64) -> f64;
pure fn exp2(n: f64) -> f64;
#[link_name="fabs"] pure fn abs(n: f64) -> f64;
#[link_name="fdim"] pure fn sub_pos(a: f64, b: f64) -> f64;
pure fn floor(n: f64) -> f64;
#[link_name="fma"] pure fn mul_add(a: f64, b: f64, c: f64) -> f64;
#[link_name="fmax"] pure fn max(a: f64, b: f64) -> f64;
#[link_name="fmin"] pure fn min(a: f64, b: f64) -> f64;
pure fn nextafter(x: f64, y: f64) -> f64
pure fn fmod(x: f64, y: f64) -> f64;
pure fn frexp(n: f64, &value: c_int) -> f64;
pure fn hypot(x: f64, y: f64) -> f64;
pure fn ldexp(x: f64, n: c_int) -> f64;
#[link_name="lgamma_r"] pure fn lgamma(n: f64, sign: *c_int) -> f64;
#[link_name="log"] pure fn ln(n: f64) -> f64;
pure fn logb(n: f64) -> f64;
#[link_name="log1p"] pure fn ln1p(n: f64) -> f64;
pure fn log10(n: f64) -> f64;
pure fn log2(n: f64) -> f64;
pure fn ilogb(n: f64) -> c_int;
pure fn modf(n: f64, iptr: *f64) -> f64;
pure fn pow(n: f64, e: f64) -> f64;
#[link_name="remainder"] pure fn rem(a: f64, b: f64) -> f64;
pure fn rint(n: f64) -> f64;
pure fn round(n: f64) -> f64;
pure fn sin(n: f64) -> f64;
pure fn sinh(n: f64) -> f64;
pure fn sqrt(n: f64) -> f64;
pure fn tan(n: f64) -> f64;
pure fn tanh(n: f64) -> f64;
pure fn tgamma(n: f64) -> f64;
pure fn trunc(n: f64) -> f64;
pure fn acos(n: c_double) -> c_double;
pure fn asin(n: c_double) -> c_double;
pure fn atan(n: c_double) -> c_double;
pure fn atan2(a: c_double, b: c_double) -> c_double;
pure fn cbrt(n: c_double) -> c_double;
pure fn ceil(n: c_double) -> c_double;
pure fn cos(n: c_double) -> c_double;
pure fn cosh(n: c_double) -> c_double;
pure fn erf(n: c_double) -> c_double;
pure fn erfc(n: c_double) -> c_double;
pure fn exp(n: c_double) -> c_double;
pure fn expm1(n: c_double) -> c_double;
pure fn exp2(n: c_double) -> c_double;
#[link_name="fabs"] pure fn abs(n: c_double) -> c_double;
#[link_name="fdim"] pure fn sub_pos(a: c_double, b: c_double) -> c_double;
pure fn floor(n: c_double) -> c_double;
#[link_name="fma"] pure fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
#[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double;
#[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double;
pure fn nextafter(x: c_double, y: c_double) -> c_double;
#[link_name="fmod"] pure fn rem(x: c_double, y: c_double) -> c_double;
pure fn frexp(n: c_double, &value: c_int) -> c_double;
pure fn hypot(x: c_double, y: c_double) -> c_double;
pure fn ldexp(x: c_double, n: c_int) -> c_double;
#[link_name="lgamma_r"] pure fn lgamma(n: c_double, &sign: c_int) -> c_double;
#[link_name="log"] pure fn ln(n: c_double) -> c_double;
pure fn logb(n: c_double) -> c_double;
#[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
pure fn log10(n: c_double) -> c_double;
pure fn log2(n: c_double) -> c_double;
pure fn ilogb(n: c_double) -> c_int;
pure fn modf(n: c_double, &iptr: c_double) -> c_double;
pure fn pow(n: c_double, e: c_double) -> c_double;
pure fn rint(n: c_double) -> c_double;
pure fn round(n: c_double) -> c_double;
pure fn sin(n: c_double) -> c_double;
pure fn sinh(n: c_double) -> c_double;
pure fn sqrt(n: c_double) -> c_double;
pure fn tan(n: c_double) -> c_double;
pure fn tanh(n: c_double) -> c_double;
pure fn tgamma(n: c_double) -> c_double;
pure fn trunc(n: c_double) -> c_double;
}
#[link_name = "m"]
#[abi = "cdecl"]
native mod f32 {
native mod c_float {
// Alpabetically sorted by link_name
#[link_name="acosf"] pure fn acos(n: f32) -> f32;
#[link_name="asinf"] pure fn asin(n: f32) -> f32;
#[link_name="atanf"] pure fn atan(n: f32) -> f32;
#[link_name="atan2f"] pure fn atan2(a: f32, b: f32) -> f32;
#[link_name="cbrtf"] pure fn cbrt(n: f32) -> f32;
#[link_name="ceilf"] pure fn ceil(n: f32) -> f32;
#[link_name="cosf"] pure fn cos(n: f32) -> f32;
#[link_name="coshf"] pure fn cosh(n: f32) -> f32;
#[link_name="erff"] pure fn erf(n: f32) -> f32;
#[link_name="erfcf"] pure fn erfc(n: f32) -> f32;
#[link_name="expf"] pure fn exp(n: f32) -> f32;
#[link_name="expm1f"]pure fn expm1(n: f32) -> f32;
#[link_name="exp2f"] pure fn exp2(n: f32) -> f32;
#[link_name="fabsf"] pure fn abs(n: f32) -> f32;
#[link_name="fdimf"] pure fn sub_pos(a: f32, b: f32) -> f32;
#[link_name="floorf"] pure fn floor(n: f32) -> f32;
#[link_name="frexpf"] pure fn frexp(n: f64, &value: c_int) -> f32;
#[link_name="fmaf"] pure fn mul_add(a: f32, b: f32, c: f32) -> f32;
#[link_name="fmaxf"] pure fn max(a: f32, b: f32) -> f32;
#[link_name="fminf"] pure fn min(a: f32, b: f32) -> f32;
#[link_name="nextafterf"] pure fn nextafter(x: f32, y: f32) -> f32
#[link_name="fmodf"] pure fn fmod(x: f32, y: f32) -> f32;
#[link_name="hypotf"] pure fn hypot(x: f32, y: f32) -> f32;
#[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32;
#[link_name="lgammaf_r"] pure fn lgamma(n: f32, sign: *c_int) -> f32;
#[link_name="logf"] pure fn ln(n: f32) -> f32;
#[link_name="logbf"] pure fn logb(n: f32) -> f32;
#[link_name="log1p"] pure fn ln1p(n: f64) -> f64;
#[link_name="log2f"] pure fn log2(n: f32) -> f32;
#[link_name="log10f"] pure fn log10(n: f32) -> f32;
#[link_name="ilogbf"] pure fn ilogb(n: f32) -> c_int;
#[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32;
#[link_name="powf"] pure fn pow(n: f32, e: f32) -> f32;
#[link_name="remainderf"] pure fn rem(a: f32, b: f32) -> f32;
#[link_name="rintf"] pure fn rint(n: f32) -> f32;
#[link_name="roundf"] pure fn round(n: f32) -> f32;
#[link_name="sinf"] pure fn sin(n: f32) -> f32;
#[link_name="sinhf"] pure fn sinh(n: f32) -> f32;
#[link_name="sqrtf"] pure fn sqrt(n: f32) -> f32;
#[link_name="tanf"] pure fn tan(n: f32) -> f32;
#[link_name="tanhf"] pure fn tanh(n: f32) -> f32;
#[link_name="tgammaf"] pure fn tgamma(n: f32) -> f32;
#[link_name="truncf"] pure fn trunc(n: f32) -> f32;
#[link_name="acosf"] pure fn acos(n: c_float) -> c_float;
#[link_name="asinf"] pure fn asin(n: c_float) -> c_float;
#[link_name="atanf"] pure fn atan(n: c_float) -> c_float;
#[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float;
#[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float;
#[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float;
#[link_name="cosf"] pure fn cos(n: c_float) -> c_float;
#[link_name="coshf"] pure fn cosh(n: c_float) -> c_float;
#[link_name="erff"] pure fn erf(n: c_float) -> c_float;
#[link_name="erfcf"] pure fn erfc(n: c_float) -> c_float;
#[link_name="expf"] pure fn exp(n: c_float) -> c_float;
#[link_name="expm1f"]pure fn expm1(n: c_float) -> c_float;
#[link_name="exp2f"] pure fn exp2(n: c_float) -> c_float;
#[link_name="fabsf"] pure fn abs(n: c_float) -> c_float;
#[link_name="fdimf"] pure fn sub_pos(a: c_float, b: c_float) -> c_float;
#[link_name="floorf"] pure fn floor(n: c_float) -> c_float;
#[link_name="frexpf"] pure fn frexp(n: c_double, &value: c_int) -> c_float;
#[link_name="fmaf"] pure fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
#[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float;
#[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float;
#[link_name="nextafterf"] pure fn nextafter(x: c_float, y: c_float) -> c_float;
#[link_name="fmodf"] pure fn rem(x: c_float, y: c_float) -> c_float;
#[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
#[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float, &sign: c_int) -> c_float;
#[link_name="logf"] pure fn ln(n: c_float) -> c_float;
#[link_name="logbf"] pure fn logb(n: c_float) -> c_float;
#[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
#[link_name="log2f"] pure fn log2(n: c_float) -> c_float;
#[link_name="log10f"] pure fn log10(n: c_float) -> c_float;
#[link_name="ilogbf"] pure fn ilogb(n: c_float) -> c_int;
#[link_name="modff"] pure fn modf(n: c_float, &iptr: c_float) -> c_float;
#[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float;
#[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
#[link_name="roundf"] pure fn round(n: c_float) -> c_float;
#[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
#[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
#[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
#[link_name="tanf"] pure fn tan(n: c_float) -> c_float;
#[link_name="tanhf"] pure fn tanh(n: c_float) -> c_float;
#[link_name="tgammaf"] pure fn tgamma(n: c_float) -> c_float;
#[link_name="truncf"] pure fn trunc(n: c_float) -> c_float;
}
#[link_name = "m"]
#[abi = "cdecl"]
native mod bessel {
pure fn j0(n: m_float) -> m_float;
pure fn j1(n: m_float) -> m_float;
pure fn jn(i: c_int, n: m_float) -> m_float;
pure fn j0(n: c_double) -> c_double;
pure fn j1(n: c_double) -> c_double;
pure fn jn(i: c_int, n: c_double) -> c_double;
pure fn y0(n: m_float) -> m_float;
pure fn y1(n: m_float) -> m_float;
pure fn yn(i: c_int, n: m_float) -> m_float;
pure fn y0(n: c_double) -> c_double;
pure fn y1(n: c_double) -> c_double;
pure fn yn(i: c_int, n: c_double) -> c_double;
}
//

View File

@ -9,6 +9,8 @@ FIXME: Add a test that uses some native code to verify these sizes,
which are not obviously correct for all potential platforms.
*/
// PORT adapt to architecture
/*
Type: c_int
@ -72,6 +74,20 @@ when interoperating with C void pointers can help in documentation.
*/
type void = int;
/*
Type: c_float
A float value with the same size as a C `float`
*/
type c_float = f32;
/*
Type: c_float
A float value with the same size as a C `double`
*/
type c_double = f64;
/*
Type: size_t
@ -115,4 +131,3 @@ An unsigned integer with the same size as a C enum
*/
type enum = u32;

View File

@ -8,17 +8,108 @@ This exposes the same operations as `math`, just for `f32` even though
they do not show up in the docs right now!
*/
import cmath::f32::*;
export t;
export
acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod,
frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin,
sinh, sqrt, tan, tanh, trunc, t;
acos,
asin,
atan,
atan2,
cbrt,
ceil,
cos,
cosh,
erf,
erfc,
exp,
expm1,
exp2,
abs,
sub_pos,
floor,
mul_add,
fmax,
fmin,
nextafter,
frexp,
hypot,
ldexp,
lgamma,
ln,
logb,
ln1p,
log10,
log2,
ilogb,
modf,
pow,
rem,
rint,
round,
sin,
sinh,
sqrt,
tan,
tanh,
tgamma,
trunc;
export consts;
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
min_exp, max_exp, min_10_exp, max_10_exp;
export consts;
// PORT
import cops = cmath::c_float;
type t = f64;
import
cops::acos,
cops::asin,
cops::atan,
cops::atan2,
cops::cbrt,
cops::ceil,
cops::cos,
cops::cosh,
cops::erf,
cops::erfc,
cops::exp,
cops::expm1,
cops::exp2,
cops::abs,
cops::sub_pos,
cops::floor,
cops::mul_add,
cops::max,
cops::min,
cops::nextafter,
cops::fmod,
cops::frexp,
cops::hypot,
cops::ldexp,
cops::lgamma,
cops::ln,
cops::logb,
cops::ln1p,
cops::log10,
cops::log2,
cops::ilogb,
cops::modf,
cops::pow,
cops::rem,
cops::rint,
cops::round,
cops::sin,
cops::sinh,
cops::sqrt,
cops::tan,
cops::tanh,
cops::tgamma,
cops::trunc;
type t = f32;

View File

@ -8,20 +8,108 @@ This exposes the same operations as `math`, just for `f64` even though
they do not show up in the docs right now!
*/
import cmath::f64::*;
export t;
export
acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod,
frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin,
sinh, sqrt, tan, tanh, trunc, t;
acos,
asin,
atan,
atan2,
cbrt,
ceil,
cos,
cosh,
erf,
erfc,
exp,
expm1,
exp2,
abs,
sub_pos,
floor,
mul_add,
fmax,
fmin,
nextafter,
frexp,
hypot,
ldexp,
lgamma,
ln,
logb,
ln1p,
log10,
log2,
ilogb,
modf,
pow,
rem,
rint,
round,
sin,
sinh,
sqrt,
tan,
tanh,
tgamma,
trunc;
export consts;
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
min_exp, max_exp, min_10_exp, max_10_exp;
export consts;
// PORT
import cops = cmath::c_double;
type t = f64;
import
cops::acos,
cops::asin,
cops::atan,
cops::atan2,
cops::cbrt,
cops::ceil,
cops::cos,
cops::cosh,
cops::erf,
cops::erfc,
cops::exp,
cops::expm1,
cops::exp2,
cops::abs,
cops::sub_pos,
cops::floor,
cops::mul_add,
cops::max,
cops::min,
cops::nextafter,
cops::fmod,
cops::frexp,
cops::hypot,
cops::ldexp,
cops::lgamma,
cops::ln,
cops::logb,
cops::ln1p,
cops::log10,
cops::log2,
cops::ilogb,
cops::modf,
cops::pow,
cops::rem,
cops::rint,
cops::round,
cops::sin,
cops::sinh,
cops::sqrt,
cops::tan,
cops::tanh,
cops::tgamma,
cops::trunc;
/* Module: consts */
mod consts {

View File

@ -10,9 +10,51 @@ export t;
export consts;
export
acos, asin, atan, atan2, ceil, cos, cosh, exp, abs, floor, fmod, frexp,
ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin, sinh, sqrt,
tan, tanh, trunc;
acos,
asin,
atan,
atan2,
cbrt,
ceil,
cos,
cosh,
erf,
erfc,
exp,
expm1,
exp2,
abs,
sub_pos,
floor,
mul_add,
max,
min,
nextafter,
rem,
frexp,
hypot,
ldexp,
lgamma,
ln,
logb,
ln1p,
log10,
log2,
ilogb,
modf,
pow,
rint,
round,
sin,
sinh,
sqrt,
tan,
tanh,
tgamma,
trunc;
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
min_exp, max_exp, min_10_exp, max_10_exp;
export to_str_common, to_str_exact, to_str, from_str;
export lt, le, eq, ne, gt, eq;
@ -27,9 +69,9 @@ import ctypes::c_int;
import ptr;
// PORT This must match in width according to architecture
import f64;
import m_float = f64;
type t = m_float;
/**

View File

@ -41,11 +41,11 @@ Machine type equivalent of a float
*/
type m_float = f64;
// PORT *must* match "import m_complex = ..." in std::complex per arch
/*
FIXME Type m_complex
// PORT *must* match "import m_complex = ..." in core::complex per arch
Machine type representing a complex value that uses floats for
both the real and the imaginary part.
*/

Binary file not shown.