else if ((prop = Fget (predicate, Qrange), !NILP (prop)))
{
Lisp_Object min = XCAR (prop), max = XCDR (prop);
-
- if (!NUMBERP (newval)
- || !NILP (arithcompare (newval, min, ARITH_LESS))
- || !NILP (arithcompare (newval, max, ARITH_GRTR)))
+ if (! NUMBERP (newval)
+ || NILP (CALLN (Fleq, min, newval, max)))
wrong_range (min, max, newval);
}
else if (FUNCTIONP (predicate))
}
/* Convert the cons-of-integers, integer, or float value C to an
- unsigned value with maximum value MAX. Signal an error if C does not
- have a valid format or is out of range. */
+ unsigned value with maximum value MAX, where MAX is one less than a
+ power of 2. Signal an error if C does not have a valid format or
+ is out of range. */
uintmax_t
cons_to_unsigned (Lisp_Object c, uintmax_t max)
{
- bool valid = 0;
+ bool valid = false;
uintmax_t val;
if (INTEGERP (c))
{
else if (FLOATP (c))
{
double d = XFLOAT_DATA (c);
- if (0 <= d
- && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
+ if (0 <= d && d < 1.0 + max)
{
val = d;
- valid = 1;
+ valid = val == d;
}
}
else if (CONSP (c) && NATNUMP (XCAR (c)))
{
uintmax_t mid = XFASTINT (XCAR (rest));
val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest));
- valid = 1;
+ valid = true;
}
else if (top <= UINTMAX_MAX >> 16)
{
if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16)
{
val = top << 16 | XFASTINT (rest);
- valid = 1;
+ valid = true;
}
}
}
if (! (valid && val <= max))
- error ("Not an in-range integer, float, or cons of integers");
+ error ("Not an in-range integer, integral float, or cons of integers");
return val;
}
/* Convert the cons-of-integers, integer, or float value C to a signed
- value with extrema MIN and MAX. Signal an error if C does not have
- a valid format or is out of range. */
+ value with extrema MIN and MAX. MAX should be one less than a
+ power of 2, and MIN should be zero or the negative of a power of 2.
+ Signal an error if C does not have a valid format or is out of
+ range. */
intmax_t
cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max)
{
- bool valid = 0;
+ bool valid = false;
intmax_t val;
if (INTEGERP (c))
{
val = XINT (c);
- valid = 1;
+ valid = true;
}
else if (FLOATP (c))
{
double d = XFLOAT_DATA (c);
- if (min <= d
- && d < (max == INTMAX_MAX ? (double) INTMAX_MAX + 1 : max + 1))
+ if (min <= d && d < 1.0 + max)
{
val = d;
- valid = 1;
+ valid = val == d;
}
}
else if (CONSP (c) && INTEGERP (XCAR (c)))
{
intmax_t mid = XFASTINT (XCAR (rest));
val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest));
- valid = 1;
+ valid = true;
}
else if (INTMAX_MIN >> 16 <= top && top <= INTMAX_MAX >> 16)
{
if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16)
{
val = top << 16 | XFASTINT (rest);
- valid = 1;
+ valid = true;
}
}
}
if (! (valid && min <= val && val <= max))
- error ("Not an in-range integer, float, or cons of integers");
+ error ("Not an in-range integer, integral float, or cons of integers");
return val;
}
\f
if (FLOATP (val))
{
double v = XFLOAT_DATA (val);
- if (0 <= v
- && (sizeof (off_t) < sizeof v
- ? v <= TYPE_MAXIMUM (off_t)
- : v < TYPE_MAXIMUM (off_t)))
- return v;
+ if (0 <= v && v < 1.0 + TYPE_MAXIMUM (off_t))
+ {
+ off_t o = v;
+ if (o == v)
+ return o;
+ }
}
wrong_type_argument (intern ("file-offset"), val);
doc: /* Return t if (car A) is numerically less than (car B). */)
(Lisp_Object a, Lisp_Object b)
{
- return CALLN (Flss, Fcar (a), Fcar (b));
+ return arithcompare (Fcar (a), Fcar (b), ARITH_LESS);
}
/* Build the complete list of annotations appropriate for writing out
--- /dev/null
+;;; charset-tests.el --- Tests for charset.c
+
+;; Copyright 2017 Free Software Foundation, Inc.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest charset-decode-char ()
+ "Test decode-char."
+ (should-error (decode-char 'ascii 0.5)))
+
+(provide 'charset-tests)