New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port some math functions #311

Merged
merged 3 commits into from Sep 19, 2017
Jump to file or symbol
Failed to load files and symbols.
+47 −72
Diff settings

Always

Just for now

Copy path View file
@@ -102,6 +102,9 @@ pub use math::Fmin;
pub use math::Fquo;
pub use math::Flss;
pub use math::Fleq;
pub use math::Frem;
pub use math::Fadd1;
pub use math::Fsub1;
pub use math::arithcompare;
pub use editfns::Feobp;
pub use editfns::Fbobp;
@@ -241,6 +244,10 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*math::Sleq);
defsubr(&*math::Sgeq);
defsubr(&*math::Sneq);
defsubr(&*math::Srem);
defsubr(&*math::Sadd1);
defsubr(&*math::Ssub1);
defsubr(&*math::Slognot);
defsubr(&*numbers::Sintegerp);
defsubr(&*numbers::Sinteger_or_marker_p);
defsubr(&*numbers::Sfloatp);
Copy path View file
@@ -354,3 +354,43 @@ fn geq(args: &mut [LispObject]) -> LispObject {
fn neq(num1: LispObject, num2: LispObject) -> LispObject {
arithcompare(num1, num2, ArithComparison::Notequal)
}
/// Return remainder of X divided by Y.
/// Both must be integers or markers.
#[lisp_fn(name = "%")]
fn rem(x: LispObject, y: LispObject) -> LispObject {
let x = x.as_fixnum_coerce_marker_or_error();
let y = y.as_fixnum_coerce_marker_or_error();
if y == 0 {
xsignal!(Qarith_error);
}
LispObject::from_fixnum(x % y)
}
/// Return NUMBER plus one. NUMBER may be a number or a marker.
/// Markers are converted to integers.
#[lisp_fn(name = "1+")]
fn add1(number: LispObject) -> LispObject {
match number.as_number_coerce_marker_or_error() {
LispNumber::Fixnum(num) => LispObject::from_fixnum(num + 1),
LispNumber::Float(num) => LispObject::from_float(num + 1.0),
}
}
/// Return NUMBER minus one. NUMBER may be a number or a marker.
/// Markers are converted to integers.
#[lisp_fn(name = "1-")]
fn sub1(number: LispObject) -> LispObject {
match number.as_number_coerce_marker_or_error() {
LispNumber::Fixnum(num) => LispObject::from_fixnum(num - 1),
LispNumber::Float(num) => LispObject::from_float(num - 1.0),
}
}
/// Return the bitwise complement of NUMBER. NUMBER must be an integer.
#[lisp_fn]
fn lognot(number: LispObject) -> LispObject {
LispObject::from_fixnum(!number.as_fixnum_or_error())

This comment has been minimized.

@birkenfeld

birkenfeld Sep 18, 2017

Collaborator

I think this needs to be from_fixnum_truncated.

This comment has been minimized.

@shanavas786

shanavas786 Sep 18, 2017

Collaborator

travis failure was due to format errors,
why do you think from_fixnum_truncated is needed here ?

This comment has been minimized.

@birkenfeld

birkenfeld Sep 19, 2017

Collaborator

never mind, I was thinking about unsigned integers.

}
Copy path View file
@@ -2231,37 +2231,6 @@ If the base used is not 10, STRING is always parsed as an integer. */)
return NILP (val) ? make_number (0) : val;
}
enum arithop
{
Aadd,
Asub,
Amult,
Adiv,
Alogand,
Alogior,
Alogxor
};
#ifndef isnan
# define isnan(x) ((x) != (x))
#endif
DEFUN ("%", Frem, Srem, 2, 2, 0,
doc: /* Return remainder of X divided by Y.
Both must be integers or markers. */)
(register Lisp_Object x, Lisp_Object y)
{
Lisp_Object val;
CHECK_NUMBER_COERCE_MARKER (x);
CHECK_NUMBER_COERCE_MARKER (y);
if (XINT (y) == 0)
xsignal0 (Qarith_error);
XSETINT (val, XINT (x) % XINT (y));
return val;
}
static Lisp_Object
ash_lsh_impl (Lisp_Object value, Lisp_Object count, bool lsh)
@@ -2304,43 +2273,6 @@ In this case, zeros are shifted in on the left. */)
return ash_lsh_impl (value, count, true);
}
DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
Markers are converted to integers. */)
(register Lisp_Object number)
{
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
if (FLOATP (number))
return (make_float (1.0 + XFLOAT_DATA (number)));
XSETINT (number, XINT (number) + 1);
return number;
}
DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
Markers are converted to integers. */)
(register Lisp_Object number)
{
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
if (FLOATP (number))
return (make_float (-1.0 + XFLOAT_DATA (number)));
XSETINT (number, XINT (number) - 1);
return number;
}
DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
(register Lisp_Object number)
{
CHECK_NUMBER (number);
XSETINT (number, ~XINT (number));
return number;
}
DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
doc: /* Return the byteorder for the machine.
Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
@@ -2905,12 +2837,8 @@ syms_of_data (void)
defsubr (&Saset);
defsubr (&Snumber_to_string);
defsubr (&Sstring_to_number);
defsubr (&Srem);
defsubr (&Slsh);
defsubr (&Sash);
defsubr (&Sadd1);
defsubr (&Ssub1);
defsubr (&Slognot);
defsubr (&Sbyteorder);
defsubr (&Ssubr_arity);
defsubr (&Ssubr_name);
ProTip! Use n and p to navigate between commits in a pull request.