diff options
| author | Richard M. Stallman | 1998-02-02 01:09:35 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-02 01:09:35 +0000 |
| commit | 7f45de2dfc7bbfc68fd850f5ed55273f151a501d (patch) | |
| tree | 6a644c712adba60e575a33870f23b058e5043849 | |
| parent | eb659c4114db8acca4632859bae2cae07c6c6e46 (diff) | |
| download | emacs-7f45de2dfc7bbfc68fd850f5ed55273f151a501d.tar.gz emacs-7f45de2dfc7bbfc68fd850f5ed55273f151a501d.zip | |
(float_to_string): Handle infinities and NaN specially.
| -rw-r--r-- | src/print.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c index a9c83ea821d..e3fbc393fea 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -956,6 +956,26 @@ float_to_string (buf, data) | |||
| 956 | unsigned char *cp; | 956 | unsigned char *cp; |
| 957 | int width; | 957 | int width; |
| 958 | 958 | ||
| 959 | /* Check for plus infinity in a way that won't lose | ||
| 960 | if there is no plus infinity. */ | ||
| 961 | if (data == data / 2 && data > 1.0) | ||
| 962 | { | ||
| 963 | strcpy (buf, "1.0e+INF"); | ||
| 964 | return; | ||
| 965 | } | ||
| 966 | /* Likewise for minus infinity. */ | ||
| 967 | if (data == data / 2 && data < -1.0) | ||
| 968 | { | ||
| 969 | strcpy (buf, "-1.0e+INF"); | ||
| 970 | return; | ||
| 971 | } | ||
| 972 | /* Check for NaN in a way that won't fail if there are no NaNs. */ | ||
| 973 | if (! (data * 0.0 >= 0.0)) | ||
| 974 | { | ||
| 975 | strcpy (buf, "0.0e+NaN"); | ||
| 976 | return; | ||
| 977 | } | ||
| 978 | |||
| 959 | if (NILP (Vfloat_output_format) | 979 | if (NILP (Vfloat_output_format) |
| 960 | || !STRINGP (Vfloat_output_format)) | 980 | || !STRINGP (Vfloat_output_format)) |
| 961 | lose: | 981 | lose: |