OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [efgcvt.c] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
FUNCTION
3
<<ecvt>>, <<ecvtf>>, <<fcvt>>, <<fcvtf>>---double or float to string
4
 
5
INDEX
6
        ecvt
7
INDEX
8
        ecvtf
9
INDEX
10
        fcvt
11
INDEX
12
        fcvtf
13
 
14
ANSI_SYNOPSIS
15
        #include <stdlib.h>
16
 
17
        char *ecvt(double <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
18
        char *ecvtf(float <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
19
 
20
        char *fcvt(double <[val]>, int <[decimals]>,
21
                   int *<[decpt]>, int *<[sgn]>);
22
        char *fcvtf(float <[val]>, int <[decimals]>,
23
                    int *<[decpt]>, int *<[sgn]>);
24
 
25
TRAD_SYNOPSIS
26
        #include <stdlib.h>
27
 
28
        char *ecvt(<[val]>, <[chars]>, <[decpt]>, <[sgn]>);
29
        double <[val]>;
30
        int <[chars]>;
31
        int *<[decpt]>;
32
        int *<[sgn]>;
33
        char *ecvtf(<[val]>, <[chars]>, <[decpt]>, <[sgn]>);
34
        float <[val]>;
35
        int <[chars]>;
36
        int *<[decpt]>;
37
        int *<[sgn]>;
38
 
39
        char *fcvt(<[val]>, <[decimals]>, <[decpt]>, <[sgn]>);
40
        double <[val]>;
41
        int <[decimals]>;
42
        int *<[decpt]>;
43
        int *<[sgn]>;
44
        char *fcvtf(<[val]>, <[decimals]>, <[decpt]>, <[sgn]>);
45
        float <[val]>;
46
        int <[decimals]>;
47
        int *<[decpt]>;
48
        int *<[sgn]>;
49
 
50
DESCRIPTION
51
<<ecvt>> and <<fcvt>> produce (null-terminated) strings of digits
52
representating the <<double>> number <[val]>.
53
<<ecvtf>> and <<fcvtf>> produce the corresponding character
54
representations of <<float>> numbers.
55
 
56
(The <<stdlib>> functions <<ecvtbuf>> and <<fcvtbuf>> are reentrant
57
versions of <<ecvt>> and <<fcvt>>.)
58
 
59
The only difference between <<ecvt>> and <<fcvt>> is the
60
interpretation of the second argument (<[chars]> or <[decimals]>).
61
For <<ecvt>>, the second argument <[chars]> specifies the total number
62
of characters to write (which is also the number of significant digits
63
in the formatted string, since these two functions write only digits).
64
For <<fcvt>>, the second argument <[decimals]> specifies the number of
65
characters to write after the decimal point; all digits for the integer
66
part of <[val]> are always included.
67
 
68
Since <<ecvt>> and <<fcvt>> write only digits in the output string,
69
they record the location of the decimal point in <<*<[decpt]>>>, and
70
the sign of the number in <<*<[sgn]>>>.  After formatting a number,
71
<<*<[decpt]>>> contains the number of digits to the left of the
72
decimal point.  <<*<[sgn]>>> contains <<0>> if the number is positive,
73
and <<1>> if it is negative.
74
 
75
RETURNS
76
All four functions return a pointer to the new string containing a
77
character representation of <[val]>.
78
 
79
PORTABILITY
80
None of these functions are ANSI C.
81
 
82
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
83
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
84
 
85
NEWPAGE
86
FUNCTION
87
<<gvcvt>>, <<gcvtf>>---format double or float as string
88
 
89
INDEX
90
        gcvt
91
INDEX
92
        gcvtf
93
 
94
ANSI_SYNOPSIS
95
        #include <stdlib.h>
96
 
97
        char *gcvt(double <[val]>, int <[precision]>, char *<[buf]>);
98
        char *gcvtf(float <[val]>, int <[precision]>, char *<[buf]>);
99
 
100
TRAD_SYNOPSIS
101
        #include <stdlib.h>
102
 
103
        char *gcvt(<[val]>, <[precision]>, <[buf]>);
104
        double <[val]>;
105
        int <[precision]>;
106
        char *<[buf]>;
107
        char *gcvtf(<[val]>, <[precision]>, <[buf]>);
108
        float <[val]>;
109
        int <[precision]>;
110
        char *<[buf]>;
111
 
112
DESCRIPTION
113
<<gcvt>> writes a fully formatted number as a null-terminated
114
string in the buffer <<*<[buf]>>>.  <<gdvtf>> produces corresponding
115
character representations of <<float>> numbers.
116
 
117
<<gcvt>> uses the same rules as the <<printf>> format
118
`<<%.<[precision]>g>>'---only negative values are signed (with
119
`<<->>'), and either exponential or ordinary decimal-fraction format
120
is chosen depending on the number of significant digits (specified by
121
<[precision]>).
122
 
123
RETURNS
124
The result is a pointer to the formatted representation of <[val]>
125
(the same as the argument <[buf]>).
126
 
127
PORTABILITY
128
Neither function is ANSI C.
129
 
130
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
131
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
132
*/
133
 
134
#include <_ansi.h>
135
#include <reent.h>
136
#include <stdio.h>
137
#include <stdlib.h>
138
#include "local.h"
139
 
140
char *
141
_DEFUN (fcvt, (d, ndigit, decpt, sign),
142
        double d _AND
143
        int ndigit _AND
144
        int *decpt _AND
145
        int *sign)
146
{
147
  return fcvtbuf (d, ndigit, decpt, sign, NULL);
148
}
149
 
150
char *
151
_DEFUN (fcvtf, (d, ndigit, decpt, sign),
152
        float d _AND
153
        int ndigit _AND
154
        int *decpt _AND
155
        int *sign)
156
{
157
  return fcvt ((float) d, ndigit, decpt, sign);
158
}
159
 
160
 
161
char *
162
_DEFUN (gcvtf, (d, ndigit, buf),
163
        float d _AND
164
        int ndigit _AND
165
        char *buf)
166
{
167
  double asd = d;
168
  return gcvt (asd, ndigit, buf);
169
}
170
 
171
 
172
char *
173
_DEFUN (ecvt, (d, ndigit, decpt, sign),
174
        double d _AND
175
        int ndigit _AND
176
        int *decpt _AND
177
        int *sign)
178
{
179
  return ecvtbuf (d, ndigit, decpt, sign, NULL);
180
}
181
 
182
char *
183
_DEFUN (ecvtf, (d, ndigit, decpt, sign),
184
        float d _AND
185
        int ndigit _AND
186
        int *decpt _AND
187
        int *sign)
188
{
189
  return ecvt ((double) d, ndigit, decpt, sign);
190
}
191
 
192
 
193
char *
194
_DEFUN (gcvt, (d, ndigit, buf),
195
        double d _AND
196
        int ndigit _AND
197
        char *buf)
198
{
199
  char *tbuf = buf;
200
  if (d < 0) {
201
    *buf = '-';
202
    buf++;
203
    ndigit--;
204
  }
205
  return (_gcvt (_REENT, d, ndigit, buf, 'g', 0) ? tbuf : 0);
206
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.