Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563642 views
1
/* Support for operator<< routines.
2
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.
6
7
Copyright 2001 Free Software Foundation, Inc.
8
9
This file is part of the GNU MP Library.
10
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 2.1 of the License, or (at your
14
option) any later version.
15
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.
20
21
You should have received a copy of the GNU Lesser General Public License
22
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
23
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
MA 02110-1301, USA. */
25
26
#include <iostream>
27
#include <stdarg.h> /* for va_list and hence doprnt_funs_t */
28
#include <string.h>
29
30
#include "gmp.h"
31
#include "gmp-impl.h"
32
33
using namespace std;
34
35
36
/* Don't need "format" for operator<< routines, just "memory" and "reps".
37
Omitting gmp_asprintf_format lets us avoid dragging vsnprintf into the
38
link. __gmp_asprintf_final will be called directly and doesn't need to
39
be in the struct. */
40
41
const struct doprnt_funs_t __gmp_asprintf_funs_noformat = {
42
NULL,
43
(doprnt_memory_t) __gmp_asprintf_memory,
44
(doprnt_reps_t) __gmp_asprintf_reps,
45
NULL
46
};
47
48
49
void
50
__gmp_doprnt_params_from_ios (struct doprnt_params_t *p, ios &o)
51
{
52
if ((o.flags() & ios::basefield) == ios::hex)
53
{
54
p->expfmt = "@%c%02d";
55
p->base = (o.flags() & ios::uppercase ? -16 : 16);
56
}
57
else
58
{
59
p->expfmt = (o.flags() & ios::uppercase ? "E%c%02d" : "e%c%02d");
60
if ((o.flags() & ios::basefield) == ios::oct)
61
p->base = 8;
62
else
63
p->base = 10;
64
}
65
66
/* "general" if none or more than one bit set */
67
if ((o.flags() & ios::floatfield) == ios::fixed)
68
p->conv = DOPRNT_CONV_FIXED;
69
else if ((o.flags() & ios::floatfield) == ios::scientific)
70
p->conv = DOPRNT_CONV_SCIENTIFIC;
71
else
72
p->conv = DOPRNT_CONV_GENERAL;
73
74
p->exptimes4 = 0;
75
76
p->fill = o.fill();
77
78
/* "right" if more than one bit set */
79
if ((o.flags() & ios::adjustfield) == ios::left)
80
p->justify = DOPRNT_JUSTIFY_LEFT;
81
else if ((o.flags() & ios::adjustfield) == ios::internal)
82
p->justify = DOPRNT_JUSTIFY_INTERNAL;
83
else
84
p->justify = DOPRNT_JUSTIFY_RIGHT;
85
86
/* ios::fixed allows prec==0, others take 0 as the default 6.
87
Don't allow negatives (they do bad things to __gmp_doprnt_float_cxx). */
88
p->prec = MAX (0, o.precision());
89
if (p->prec == 0 && p->conv != DOPRNT_CONV_FIXED)
90
p->prec = 6;
91
92
/* for hex showbase is always, for octal only non-zero */
93
if (o.flags() & ios::showbase)
94
p->showbase = ((o.flags() & ios::basefield) == ios::hex
95
? DOPRNT_SHOWBASE_YES : DOPRNT_SHOWBASE_NONZERO);
96
else
97
p->showbase = DOPRNT_SHOWBASE_NO;
98
99
p->showpoint = ((o.flags() & ios::showpoint) != 0);
100
101
/* in fixed and scientific always show trailing zeros, in general format
102
show them if showpoint is set (or so it seems) */
103
if ((o.flags() & ios::floatfield) == ios::fixed
104
|| (o.flags() & ios::floatfield) == ios::scientific)
105
p->showtrailing = 1;
106
else
107
p->showtrailing = p->showpoint;
108
109
p->sign = (o.flags() & ios::showpos ? '+' : '\0');
110
111
p->width = o.width();
112
113
/* reset on each output */
114
o.width (0);
115
}
116
117