diff options
| author | Paul Eggert | 1993-08-10 04:14:17 +0000 |
|---|---|---|
| committer | Paul Eggert | 1993-08-10 04:14:17 +0000 |
| commit | 44fa9da5d7a88907a589fbb17ce7a7fee31ab291 (patch) | |
| tree | 2dadf420277eb72055e35a1238e08a9c5d07c515 /src | |
| parent | ce426daa3271b501792fab319e8c2cecac10dd98 (diff) | |
| download | emacs-44fa9da5d7a88907a589fbb17ce7a7fee31ab291.tar.gz emacs-44fa9da5d7a88907a589fbb17ce7a7fee31ab291.zip | |
(Fmod): New function; result is always same sign as divisor.
Diffstat (limited to 'src')
| -rw-r--r-- | src/data.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/data.c b/src/data.c index a829e7d80ba..5ed79c5925b 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -1752,6 +1752,60 @@ Both must be integers or markers.") | |||
| 1752 | return val; | 1752 | return val; |
| 1753 | } | 1753 | } |
| 1754 | 1754 | ||
| 1755 | DEFUN ("mod", Fmod, Smod, 2, 2, 0, | ||
| 1756 | "Returns X modulo Y.\n\ | ||
| 1757 | The result falls between zero (inclusive) and Y (exclusive).\n\ | ||
| 1758 | Both X and Y must be numbers or markers.") | ||
| 1759 | (num1, num2) | ||
| 1760 | register Lisp_Object num1, num2; | ||
| 1761 | { | ||
| 1762 | Lisp_Object val; | ||
| 1763 | int i1, i2; | ||
| 1764 | |||
| 1765 | #ifdef LISP_FLOAT_TYPE | ||
| 1766 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0); | ||
| 1767 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 1); | ||
| 1768 | |||
| 1769 | if (XTYPE (num1) == Lisp_Float || XTYPE (num2) == Lisp_Float) | ||
| 1770 | { | ||
| 1771 | double f1, f2; | ||
| 1772 | |||
| 1773 | f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1); | ||
| 1774 | f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2); | ||
| 1775 | if (f2 == 0) | ||
| 1776 | Fsignal (Qarith_error, Qnil); | ||
| 1777 | |||
| 1778 | #if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux) | ||
| 1779 | f1 = fmod (f1, f2); | ||
| 1780 | #else | ||
| 1781 | f1 = drem (f1, f2); | ||
| 1782 | #endif | ||
| 1783 | /* If the "remainder" comes out with the wrong sign, fix it. */ | ||
| 1784 | if ((f1 < 0) != (f2 < 0)) | ||
| 1785 | f1 += f2; | ||
| 1786 | return (make_float (f1)); | ||
| 1787 | } | ||
| 1788 | #else /* not LISP_FLOAT_TYPE */ | ||
| 1789 | CHECK_NUMBER_COERCE_MARKER (num1, 0); | ||
| 1790 | CHECK_NUMBER_COERCE_MARKER (num2, 1); | ||
| 1791 | #endif /* not LISP_FLOAT_TYPE */ | ||
| 1792 | |||
| 1793 | i1 = XINT (num1); | ||
| 1794 | i2 = XINT (num2); | ||
| 1795 | |||
| 1796 | if (i2 == 0) | ||
| 1797 | Fsignal (Qarith_error, Qnil); | ||
| 1798 | |||
| 1799 | i1 %= i2; | ||
| 1800 | |||
| 1801 | /* If the "remainder" comes out with the wrong sign, fix it. */ | ||
| 1802 | if ((i1 < 0) != (i2 < 0)) | ||
| 1803 | i1 += i2; | ||
| 1804 | |||
| 1805 | XSET (val, Lisp_Int, i1); | ||
| 1806 | return val; | ||
| 1807 | } | ||
| 1808 | |||
| 1755 | DEFUN ("max", Fmax, Smax, 1, MANY, 0, | 1809 | DEFUN ("max", Fmax, Smax, 1, MANY, 0, |
| 1756 | "Return largest of all the arguments (which must be numbers or markers).\n\ | 1810 | "Return largest of all the arguments (which must be numbers or markers).\n\ |
| 1757 | The value is always a number; markers are converted to numbers.") | 1811 | The value is always a number; markers are converted to numbers.") |
| @@ -2194,6 +2248,7 @@ syms_of_data () | |||
| 2194 | defsubr (&Stimes); | 2248 | defsubr (&Stimes); |
| 2195 | defsubr (&Squo); | 2249 | defsubr (&Squo); |
| 2196 | defsubr (&Srem); | 2250 | defsubr (&Srem); |
| 2251 | defsubr (&Smod); | ||
| 2197 | defsubr (&Smax); | 2252 | defsubr (&Smax); |
| 2198 | defsubr (&Smin); | 2253 | defsubr (&Smin); |
| 2199 | defsubr (&Slogand); | 2254 | defsubr (&Slogand); |