summaryrefslogtreecommitdiff
path: root/out_str.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-02-12 16:41:36 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-02-12 16:41:36 +0000
commit65f0003f33daceaaceecae05f4fe5965ae3d986a (patch)
treec4241234f08d49425772ccede4f9dd6a4136326e /out_str.c
parentdbf936ae37b2724f77df4ff737e4cf923658caa3 (diff)
downloadmpfr-65f0003f33daceaaceecae05f4fe5965ae3d986a.tar.gz
mpfr_get_str: the returned exponent for 0 is 0 (like in frexp()).
mpz_set_fr.c: comment added. out_str.c: minor changes. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1692 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'out_str.c')
-rw-r--r--out_str.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/out_str.c b/out_str.c
index 0ad99983c..964aa9951 100644
--- a/out_str.c
+++ b/out_str.c
@@ -21,6 +21,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "mpfr.h"
@@ -42,7 +43,7 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
if (MPFR_IS_INF(op))
{
- if (MPFR_SIGN(op) == 1)
+ if (MPFR_SIGN(op) > 0)
{
fprintf (stream, "Inf");
return 3;
@@ -54,20 +55,27 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
}
}
- if (!MPFR_NOTZERO(op))
+ if (MPFR_IS_ZERO(op))
{
- l = (MPFR_SIGN(op) < 0) ? fprintf (stream, "-") : 0;
- fprintf(stream, "0");
- return l + 1;
+ if (MPFR_SIGN(op) > 0)
+ {
+ fprintf(stream, "0");
+ return 1;
+ }
+ else
+ {
+ fprintf(stream, "-0");
+ return 2;
+ }
}
- if (!MPFR_NOTZERO(op)) { fprintf(stream, "0"); return 1; }
s = mpfr_get_str (NULL, &e, base, n_digits, op, rnd_mode);
s0 = s;
/* for op=3.1416 we have s = "31416" and e = 1 */
-
- l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str */
+
+ l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str
+ - may be incorrect, as only an upper bound? */
if (*s == '-')
fputc (*s++, stream);
@@ -78,9 +86,12 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
(*__gmp_free_func) (s0, l);
/* outputs exponent */
- if (e) {
- l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), e);
- }
+ if (e)
+ {
+ MPFR_ASSERTN(e >= LONG_MIN);
+ MPFR_ASSERTN(e <= LONG_MAX);
+ l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
+ }
return l;
}