diff options
Diffstat (limited to 'src/timefns.c')
| -rw-r--r-- | src/timefns.c | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/timefns.c b/src/timefns.c index 1112f174763..eed2edf1cc0 100644 --- a/src/timefns.c +++ b/src/timefns.c | |||
| @@ -401,6 +401,10 @@ decode_float_time (double t, struct lisp_time *result) | |||
| 401 | else | 401 | else |
| 402 | { | 402 | { |
| 403 | int scale = double_integer_scale (t); | 403 | int scale = double_integer_scale (t); |
| 404 | /* FIXME: `double_integer_scale` often returns values that are | ||
| 405 | "pessimistic" (i.e. larger than necessary), so 3.5 gets converted | ||
| 406 | to (7881299347898368 . 2251799813685248) rather than (7 . 2). | ||
| 407 | On 64bit systems, this should not matter very much, tho. */ | ||
| 404 | eassume (scale < flt_radix_power_size); | 408 | eassume (scale < flt_radix_power_size); |
| 405 | 409 | ||
| 406 | if (scale < 0) | 410 | if (scale < 0) |
| @@ -818,17 +822,6 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only, | |||
| 818 | 822 | ||
| 819 | if (NILP (specified_time)) | 823 | if (NILP (specified_time)) |
| 820 | form = TIMEFORM_NIL; | 824 | form = TIMEFORM_NIL; |
| 821 | else if (FLOATP (specified_time)) | ||
| 822 | { | ||
| 823 | double d = XFLOAT_DATA (specified_time); | ||
| 824 | if (!isfinite (d)) | ||
| 825 | time_error (isnan (d) ? EDOM : EOVERFLOW); | ||
| 826 | if (result) | ||
| 827 | decode_float_time (d, result); | ||
| 828 | else | ||
| 829 | *dresult = d; | ||
| 830 | return TIMEFORM_FLOAT; | ||
| 831 | } | ||
| 832 | else if (CONSP (specified_time)) | 825 | else if (CONSP (specified_time)) |
| 833 | { | 826 | { |
| 834 | high = XCAR (specified_time); | 827 | high = XCAR (specified_time); |
| @@ -868,6 +861,22 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only, | |||
| 868 | if (! INTEGERP (low)) | 861 | if (! INTEGERP (low)) |
| 869 | form = TIMEFORM_INVALID; | 862 | form = TIMEFORM_INVALID; |
| 870 | } | 863 | } |
| 864 | else if (FASTER_TIMEFNS && INTEGERP (specified_time)) | ||
| 865 | { | ||
| 866 | decode_ticks_hz (specified_time, make_fixnum (1), result, dresult); | ||
| 867 | return form; | ||
| 868 | } | ||
| 869 | else if (FLOATP (specified_time)) | ||
| 870 | { | ||
| 871 | double d = XFLOAT_DATA (specified_time); | ||
| 872 | if (!isfinite (d)) | ||
| 873 | time_error (isnan (d) ? EDOM : EOVERFLOW); | ||
| 874 | if (result) | ||
| 875 | decode_float_time (d, result); | ||
| 876 | else | ||
| 877 | *dresult = d; | ||
| 878 | return TIMEFORM_FLOAT; | ||
| 879 | } | ||
| 871 | 880 | ||
| 872 | int err = decode_time_components (form, high, low, usec, psec, | 881 | int err = decode_time_components (form, high, low, usec, psec, |
| 873 | result, dresult); | 882 | result, dresult); |
| @@ -1202,10 +1211,16 @@ time_cmp (Lisp_Object a, Lisp_Object b) | |||
| 1202 | return 0; | 1211 | return 0; |
| 1203 | 1212 | ||
| 1204 | /* Compare (X . Z) to (Y . Z) quickly if X and Y are fixnums. | 1213 | /* Compare (X . Z) to (Y . Z) quickly if X and Y are fixnums. |
| 1205 | Do not inspect Z, as it is OK to not signal if A and B are invalid. */ | 1214 | Do not inspect Z, as it is OK to not signal if A and B are invalid. |
| 1206 | if (FASTER_TIMEFNS && CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b)) | 1215 | Also, compare X to Y quickly if X and Y are fixnums. */ |
| 1207 | && FIXNUMP (XCAR (a)) && FIXNUMP (XCAR (b))) | 1216 | if (FASTER_TIMEFNS) |
| 1208 | return XFIXNUM (XCAR (a)) - XFIXNUM (XCAR (b)); | 1217 | { |
| 1218 | Lisp_Object x = a, y = b; | ||
| 1219 | if (CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b))) | ||
| 1220 | x = XCAR (a), y = XCAR (b); | ||
| 1221 | if (FIXNUMP (x) && FIXNUMP (y)) | ||
| 1222 | return XFIXNUM (x) - XFIXNUM (y); | ||
| 1223 | } | ||
| 1209 | 1224 | ||
| 1210 | /* Compare (ATICKS . AZ) to (BTICKS . BHZ) by comparing | 1225 | /* Compare (ATICKS . AZ) to (BTICKS . BHZ) by comparing |
| 1211 | ATICKS * BHZ to BTICKS * AHZ. */ | 1226 | ATICKS * BHZ to BTICKS * AHZ. */ |
| @@ -1714,21 +1729,29 @@ usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS) */) | |||
| 1714 | } | 1729 | } |
| 1715 | 1730 | ||
| 1716 | DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0, | 1731 | DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0, |
| 1717 | doc: /* Convert TIME value to a Lisp timestamp. | 1732 | doc: /* Convert TIME value to a Lisp timestamp of the given FORM. |
| 1718 | With optional FORM, convert to that timestamp form. | ||
| 1719 | Truncate the returned value toward minus infinity. | 1733 | Truncate the returned value toward minus infinity. |
| 1720 | 1734 | ||
| 1721 | If FORM is nil (the default), return the same form as `current-time'. | ||
| 1722 | If FORM is a positive integer, return a pair of integers (TICKS . FORM), | 1735 | If FORM is a positive integer, return a pair of integers (TICKS . FORM), |
| 1723 | where TICKS is the number of clock ticks and FORM is the clock frequency | 1736 | where TICKS is the number of clock ticks and FORM is the clock frequency |
| 1724 | in ticks per second. If FORM is t, return (TICKS . PHZ), where | 1737 | in ticks per second. |
| 1725 | PHZ is a suitable clock frequency in ticks per second. If FORM is | 1738 | |
| 1726 | `integer', return an integer count of seconds. If FORM is `list', | 1739 | If FORM is t, return (TICKS . PHZ), where PHZ is a suitable clock |
| 1727 | return an integer list (HIGH LOW USEC PSEC), where HIGH has the most | 1740 | frequency in ticks per second. |
| 1728 | significant bits of the seconds, LOW has the least significant 16 | 1741 | |
| 1729 | bits, and USEC and PSEC are the microsecond and picosecond counts. */) | 1742 | If FORM is `integer', return an integer count of seconds. |
| 1743 | |||
| 1744 | If FORM is `list', return an integer list (HIGH LOW USEC PSEC), where | ||
| 1745 | HIGH has the most significant bits of the seconds, LOW has the least | ||
| 1746 | significant 16 bits, and USEC and PSEC are the microsecond and | ||
| 1747 | picosecond counts. | ||
| 1748 | |||
| 1749 | If FORM is nil, the behavior depends on `current-time-list', | ||
| 1750 | but new code should not rely on it. */) | ||
| 1730 | (Lisp_Object time, Lisp_Object form) | 1751 | (Lisp_Object time, Lisp_Object form) |
| 1731 | { | 1752 | { |
| 1753 | /* FIXME: Any reason why we don't offer a `float` output format option as | ||
| 1754 | well, since we accept it as input? */ | ||
| 1732 | struct lisp_time t; | 1755 | struct lisp_time t; |
| 1733 | enum timeform input_form = decode_lisp_time (time, false, &t, 0); | 1756 | enum timeform input_form = decode_lisp_time (time, false, &t, 0); |
| 1734 | if (NILP (form)) | 1757 | if (NILP (form)) |