changeset 75181:ea255892b6fd

(Fformat): Allow integer-format to work with floats of size larger than most-positive-fixnum (but still smaller than MAXINT).
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 10 Jan 2007 03:50:19 +0000
parents cf3da57bf8a5
children 54c43f5d4c8b
files src/ChangeLog src/editfns.c
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jan 10 03:44:49 2007 +0000
+++ b/src/ChangeLog	Wed Jan 10 03:50:19 2007 +0000
@@ -1,5 +1,8 @@
 2007-01-10  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* editfns.c (Fformat): Allow integer-format to work with floats of size
+	larger than most-positive-fixnum (but still smaller than MAXINT).
+
 	* dired.c (Ffile_attributes): Use floats for large uids/gids.
 
 2007-01-09  Eli Zaretskii  <eliz@gnu.org>
--- a/src/editfns.c	Wed Jan 10 03:44:49 2007 +0000
+++ b/src/editfns.c	Wed Jan 10 03:50:19 2007 +0000
@@ -1,7 +1,7 @@
 /* Lisp functions pertaining to editing.
    Copyright (C) 1985, 1986, 1987, 1989, 1993, 1994, 1995, 1996,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006 Free Software Foundation, Inc.
+                 2005, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -3631,7 +3631,12 @@
 		if (*format != 'd' && *format != 'o' && *format != 'x'
 		    && *format != 'i' && *format != 'X' && *format != 'c')
 		  error ("Invalid format operation %%%c", *format);
-		args[n] = Ftruncate (args[n], Qnil);
+		/* This fails unnecessarily if args[n] is bigger than
+		   most-positive-fixnum but smaller than MAXINT.
+		   These cases are important because we sometimes use floats
+		   to represent such integer values (typically such values
+		   come from UIDs or PIDs).  */
+		/* args[n] = Ftruncate (args[n], Qnil); */
 	      }
 
 	    /* Note that we're using sprintf to print floats,
@@ -3799,8 +3804,15 @@
 		  else
 		    sprintf (p, this_format, XUINT (args[n]));
 		}
+	      else if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g')
+		sprintf (p, this_format, XFLOAT_DATA (args[n]));
+	      else if (format[-1] == 'd')
+		/* Maybe we should use "%1.0f" instead so it also works
+		   for values larger than MAXINT.  */
+		sprintf (p, this_format, (EMACS_INT) XFLOAT_DATA (args[n]));
 	      else
-		sprintf (p, this_format, XFLOAT_DATA (args[n]));
+		/* Don't sign-extend for octal or hex printing.  */
+		sprintf (p, this_format, (EMACS_UINT) XFLOAT_DATA (args[n]));
 
 	      if (p > buf
 		  && multibyte