Skip to content

Commit

Permalink
core: killed all math wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle committed Dec 31, 2011
1 parent 49d36c7 commit 57ac67a
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 795 deletions.
34 changes: 23 additions & 11 deletions src/libcore/cmath.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export c_double;
export c_float;
export bessel;

import ctypes::c_int;
import ctypes::c_float;
import ctypes::c_double;

// FIXME scalbn copysign

#[link_name = "m"]
#[abi = "cdecl"]
native mod c_double {
Expand All @@ -16,6 +18,7 @@ native mod 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 copysign(x: c_double, y: 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;
Expand All @@ -26,15 +29,16 @@ native mod 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="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="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;
Expand All @@ -45,6 +49,7 @@ native mod 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 scalbn(n: c_double, i: c_int) -> 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;
Expand All @@ -66,6 +71,8 @@ native mod 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="copysignf"] pure fn copysign(x: c_float,
y: 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;
Expand All @@ -76,25 +83,30 @@ native mod 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="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="nextafterf"] pure fn nextafter(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="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="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="scalbnf"] pure fn scalbn(n: c_float, i: c_int) -> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export box, char, float, f32, f64, int, str, ptr;
export uint, u8, u32, u64, vec, bool;
export either, option, result;
export ctypes, mtypes, sys, unsafe, comm, task;
export ctypes, sys, unsafe, comm, task;
export extfmt;

// Built-in-type support modules
Expand Down
185 changes: 81 additions & 104 deletions src/libcore/f32.rs
Original file line number Diff line number Diff line change
@@ -1,117 +1,94 @@

/*
Module: f32
Floating point operations and constants for `f32`
This exposes the same operations as `math`, just for `f32` even though
they do not show up in the docs right now!
*/
// PORT

export t;

export
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;
import cmath::c_float::*;

// PORT
type t = f32;

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;
/* Const: NaN */
const NaN: f32 = 0.0f32/0.0f32;

/* Const: infinity */
const infinity: f32 = 1.0f32/0.0f32;

type t = f32;
/* Const: neg_infinity */
const neg_infinity: f32 = -1.0f32/0.0f32;

/* Predicate: isNaN */
pure fn isNaN(f: f32) -> bool { f != f }

/* Function: add */
pure fn add(x: f32, y: f32) -> f32 { ret x + y; }

/* Function: sub */
pure fn sub(x: f32, y: f32) -> f32 { ret x - y; }

/* Function: mul */
pure fn mul(x: f32, y: f32) -> f32 { ret x * y; }

/* Function: div */
pure fn div(x: f32, y: f32) -> f32 { ret x / y; }

/* Function: rem */
pure fn rem(x: f32, y: f32) -> f32 { ret x % y; }

/* Predicate: lt */
pure fn lt(x: f32, y: f32) -> bool { ret x < y; }

/* Predicate: le */
pure fn le(x: f32, y: f32) -> bool { ret x <= y; }

/* Predicate: eq */
pure fn eq(x: f32, y: f32) -> bool { ret x == y; }

/* Predicate: ne */
pure fn ne(x: f32, y: f32) -> bool { ret x != y; }

/* Predicate: ge */
pure fn ge(x: f32, y: f32) -> bool { ret x >= y; }

/* Predicate: gt */
pure fn gt(x: f32, y: f32) -> bool { ret x > y; }

/*
Predicate: positive
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
*/
pure fn positive(x: f32) -> bool
{ ret x > 0.0f32 || (1.0f32/x) == infinity; }

/*
Predicate: negative
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
*/
pure fn negative(x: f32) -> bool
{ ret x < 0.0f32 || (1.0f32/x) == neg_infinity; }

/*
Predicate: nonpositive
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
(This is the same as `f32::negative`.)
*/
pure fn nonpositive(x: f32) -> bool {
ret x < 0.0f32 || (1.0f32/x) == neg_infinity;
}

/*
Predicate: nonnegative
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
(This is the same as `f32::positive`.)
*/
pure fn nonnegative(x: f32) -> bool {
ret x > 0.0f32 || (1.0f32/x) == infinity;
}

/* Module: consts */
mod consts {
Expand Down
Loading

0 comments on commit 57ac67a

Please sign in to comment.