Commit 9b4d34fa authored by Paul Eggert's avatar Paul Eggert

Improve binary-as-unsigned treatment (Bug#34792)

* etc/NEWS:
* src/editfns.c (Fformat, binary_as_unsigned):
Update now that we always have bignums.
(syms_of_editfns) [!defined lisp_h_FIXNUMP]: Remove now-obsolete
code, since lisp_h_FIXNUMP is always defined now.
* test/src/editfns-tests.el (read-large-integer): Simplify,
now that we can assume binary-as-unsigned defaults to nil.
parent e81c44fd
Pipeline #980 failed with stage
in 60 minutes and 1 second
......@@ -1490,10 +1490,10 @@ between two strings.
'(quote x)' instead of 'x you will have to bind it to nil where applicable.
+++
** Numbers formatted via '%o' or '%x' may now be formatted as signed integers.
** Numbers formatted via '%o' or '%x' are now formatted as signed integers.
This avoids problems in calls like '(read (format "#x%x" -1))', and is
more compatible with bignums, a planned feature. To get this
behavior, set the experimental variable 'binary-as-unsigned' to nil,
more compatible with bignums. To get the traditional machine-dependent
behavior, set the experimental variable 'binary-as-unsigned' to t,
and if the new behavior breaks your code please email
32252@debbugs.gnu.org. Because '%o' and '%x' can now format signed
integers, they now support the '+' and space flags.
......
......@@ -3001,8 +3001,8 @@ the next available argument, or the argument explicitly specified:
%S means print any object as an s-expression (using `prin1').
The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.
The value of `binary-as-unsigned' determines whether it's printed as
signed or unsigned by %o, %x, and %X.
%o, %x, and %X treat arguments as unsigned if `binary-as-unsigned' is t
(this is experimental; email 32252@debbugs.gnu.org if you need it).
Use %% to put a single % into the output.
A %-sequence other than %% may contain optional field number, flag,
......@@ -4485,17 +4485,13 @@ functions if all the text being accessed has this property. */);
binary_as_unsigned,
doc: /* Non-nil means `format' %x and %o treat integers as unsigned.
This has machine-dependent results. Nil means to treat integers as
signed, which is portable; for example, if N is a negative integer,
(read (format "#x%x") N) returns N only when this variable is nil.
signed, which is portable and is the default; for example, if N is a
negative integer, (read (format "#x%x") N) returns N only when this
variable is nil.
This variable is experimental; email 32252@debbugs.gnu.org if you need
it to be non-nil. */);
/* For now, default to true if bignums exist, false in traditional Emacs. */
#ifdef lisp_h_FIXNUMP
binary_as_unsigned = false;
#else
binary_as_unsigned = true;
#endif
defsubr (&Spropertize);
defsubr (&Schar_equal);
......
......@@ -184,12 +184,11 @@
'integer))
(should (eq (type-of (read (format "#32rG%x" most-positive-fixnum)))
'integer))
(let ((binary-as-unsigned nil))
(dolist (fmt '("%d" "%s" "#o%o" "#x%x"))
(dolist (val (list most-negative-fixnum (1+ most-negative-fixnum)
-1 0 1
(1- most-positive-fixnum) most-positive-fixnum))
(should (eq val (read (format fmt val))))))))
(dolist (fmt '("%d" "%s" "#o%o" "#x%x"))
(dolist (val (list most-negative-fixnum (1+ most-negative-fixnum)
-1 0 1
(1- most-positive-fixnum) most-positive-fixnum))
(should (eq val (read (format fmt val)))))))
(ert-deftest format-%o-invalid-float ()
(should-error (format "%o" -1e-37)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment