Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rust_src/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions rust_src/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be from_fixnum_truncated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I was thinking about unsigned integers.

}
72 changes: 0 additions & 72 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down