1 /* Support for operator<< routines.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2001 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25 #include <stdarg.h> /* for va_list and hence doprnt_funs_t */
34 /* Don't need "format" for operator<< routines, just "memory" and "reps".
35 Omitting gmp_asprintf_format lets us avoid dragging vsnprintf into the
36 link. __gmp_asprintf_final will be called directly and doesn't need to
39 const struct doprnt_funs_t __gmp_asprintf_funs_noformat = {
41 (doprnt_memory_t) __gmp_asprintf_memory,
42 (doprnt_reps_t) __gmp_asprintf_reps,
48 __gmp_doprnt_params_from_ios (struct doprnt_params_t *p, ios &o)
50 if ((o.flags() & ios::basefield) == ios::hex)
52 p->expfmt = "@%c%02d";
53 p->base = (o.flags() & ios::uppercase ? -16 : 16);
57 p->expfmt = (o.flags() & ios::uppercase ? "E%c%02d" : "e%c%02d");
58 if ((o.flags() & ios::basefield) == ios::oct)
64 /* "general" if none or more than one bit set */
65 if ((o.flags() & ios::floatfield) == ios::fixed)
66 p->conv = DOPRNT_CONV_FIXED;
67 else if ((o.flags() & ios::floatfield) == ios::scientific)
68 p->conv = DOPRNT_CONV_SCIENTIFIC;
70 p->conv = DOPRNT_CONV_GENERAL;
76 /* "right" if more than one bit set */
77 if ((o.flags() & ios::adjustfield) == ios::left)
78 p->justify = DOPRNT_JUSTIFY_LEFT;
79 else if ((o.flags() & ios::adjustfield) == ios::internal)
80 p->justify = DOPRNT_JUSTIFY_INTERNAL;
82 p->justify = DOPRNT_JUSTIFY_RIGHT;
84 /* ios::fixed allows prec==0, others take 0 as the default 6.
85 Don't allow negatives (they do bad things to __gmp_doprnt_float_cxx). */
86 p->prec = MAX (0, o.precision());
87 if (p->prec == 0 && p->conv != DOPRNT_CONV_FIXED)
90 /* for hex showbase is always, for octal only non-zero */
91 if (o.flags() & ios::showbase)
92 p->showbase = ((o.flags() & ios::basefield) == ios::hex
93 ? DOPRNT_SHOWBASE_YES : DOPRNT_SHOWBASE_NONZERO);
95 p->showbase = DOPRNT_SHOWBASE_NO;
97 p->showpoint = ((o.flags() & ios::showpoint) != 0);
99 /* in fixed and scientific always show trailing zeros, in general format
100 show them if showpoint is set (or so it seems) */
101 if ((o.flags() & ios::floatfield) == ios::fixed
102 || (o.flags() & ios::floatfield) == ios::scientific)
105 p->showtrailing = p->showpoint;
107 p->sign = (o.flags() & ios::showpos ? '+' : '\0');
109 p->width = o.width();
111 /* reset on each output */