aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-07-23 01:42:32 -0700
committerPaul Eggert2019-07-23 01:46:41 -0700
commitdfb0ba79b5f41ca6fed25a03d2a5cd6996ec4753 (patch)
tree87426b1fde8da618b4e7657b09bc256f5c011dcc /src
parent56a3e4a5d366a8453608d9a604ebd5ddb4e52245 (diff)
downloademacs-dfb0ba79b5f41ca6fed25a03d2a5cd6996ec4753.tar.gz
emacs-dfb0ba79b5f41ca6fed25a03d2a5cd6996ec4753.zip
Support "%x" etc. formats on more floats
* doc/lispref/strings.texi (Formatting Strings): Document this. * src/editfns.c (styled_format): Support %o, %x, and %X on finite floats less than zero or greater than UINTMAX_MAX. * test/src/editfns-tests.el (format-%x-large-float) (read-large-integer, format-%o-negative-float): Adjust tests to match extended behavior. Rename the latter test from format-%o-invalid-float, since the float is no longer invalid. * test/src/editfns-tests.el (format-%x-large-float) (read-large-integer): Test this.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 8e0c0c451e6..1b33f397110 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3594,6 +3594,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3594 sprintf_bytes = prec != 0; 3594 sprintf_bytes = prec != 0;
3595 } 3595 }
3596 else if (BIGNUMP (arg)) 3596 else if (BIGNUMP (arg))
3597 bignum_arg:
3597 { 3598 {
3598 int base = ((conversion == 'd' || conversion == 'i') ? 10 3599 int base = ((conversion == 'd' || conversion == 'i') ? 10
3599 : conversion == 'o' ? 8 : 16); 3600 : conversion == 'o' ? 8 : 16);
@@ -3655,11 +3656,17 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3655 else 3656 else
3656 { 3657 {
3657 double d = XFLOAT_DATA (arg); 3658 double d = XFLOAT_DATA (arg);
3658 double uintmax = UINTMAX_MAX; 3659 double abs_d = fabs (d);
3659 if (! (0 <= d && d < uintmax + 1)) 3660 if (abs_d < UINTMAX_MAX + 1.0)
3660 xsignal1 (Qoverflow_error, arg); 3661 {
3661 x = d; 3662 negative = d <= -1;
3662 negative = false; 3663 x = abs_d;
3664 }
3665 else
3666 {
3667 arg = double_to_integer (d);
3668 goto bignum_arg;
3669 }
3663 } 3670 }
3664 p[0] = negative ? '-' : plus_flag ? '+' : ' '; 3671 p[0] = negative ? '-' : plus_flag ? '+' : ' ';
3665 bool signedp = negative | plus_flag | space_flag; 3672 bool signedp = negative | plus_flag | space_flag;