ReactOS  0.4.13-dev-52-g0efcfec
i10output.c
Go to the documentation of this file.
1 #include <precomp.h>
2 
3 #define I10_OUTPUT_MAX_PREC 21
4 /* Internal structure used by $I10_OUTPUT */
6  short pos;
7  char sign;
9  char str[I10_OUTPUT_MAX_PREC+1]; /* add space for '\0' */
10 };
11 
12 /*********************************************************************
13  * $I10_OUTPUT (MSVCRT.@)
14  * ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
15  * prec - precision of part, we're interested in
16  * flag - 0 for first prec digits, 1 for fractional part
17  * data - data to be populated
18  *
19  * return value
20  * 0 if given double is NaN or INF
21  * 1 otherwise
22  *
23  * FIXME
24  * Native sets last byte of data->str to '0' or '9', I don't know what
25  * it means. Current implementation sets it always to '0'.
26  */
27 int CDECL MSVCRT_I10_OUTPUT(_LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
28 {
29  static const char inf_str[] = "1#INF";
30  static const char nan_str[] = "1#QNAN";
31 
32  /* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
33  * Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
34  * Assume long double uses 80 bit FP, never seen 128 bit FP. */
35  long double ld = 0;
36  double d;
37  char format[8];
38  char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
39  char *p;
40 
41  memcpy(&ld, &ld80, 10);
42  d = ld;
43  TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
44 
45  if(d<0) {
46  data->sign = '-';
47  d = -d;
48  } else
49  data->sign = ' ';
50 
51  if(!_finite(d)) {
52  data->pos = 1;
53  data->len = 5;
54  memcpy(data->str, inf_str, sizeof(inf_str));
55 
56  return 0;
57  }
58 
59  if(_isnan(d)) {
60  data->pos = 1;
61  data->len = 6;
62  memcpy(data->str, nan_str, sizeof(nan_str));
63 
64  return 0;
65  }
66 
67  if(flag&1) {
68  int exp = 1+floor(log10(d));
69 
70  prec += exp;
71  if(exp < 0)
72  prec--;
73  }
74  prec--;
75 
76  if(prec+1 > I10_OUTPUT_MAX_PREC)
77  prec = I10_OUTPUT_MAX_PREC-1;
78  else if(prec < 0) {
79  d = 0.0;
80  prec = 0;
81  }
82 
83  sprintf(format, "%%.%dle", prec);
84  sprintf(buf, format, d);
85 
86  buf[1] = buf[0];
87  data->pos = atoi(buf+prec+3);
88  if(buf[1] != '0')
89  data->pos++;
90 
91  for(p = buf+prec+1; p>buf+1 && *p=='0'; p--);
92  data->len = p-buf;
93 
94  memcpy(data->str, buf+1, data->len);
95  data->str[data->len] = '\0';
96 
97  if(buf[1]!='0' && prec-data->len+1>0)
98  memcpy(data->str+data->len+1, buf+data->len+1, prec-data->len+1);
99 
100  return 1;
101 }
102 #undef I10_OUTPUT_MAX_PREC
103 
104 
105 
_Check_return_ __MINGW_NOTHROW _CRTIMP int __cdecl _isnan(_In_ double)
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char str[I10_OUTPUT_MAX_PREC+1]
Definition: i10output.c:9
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static jsstr_t * nan_str
Definition: jsstr.c:281
#define TRACE(s)
Definition: solgame.cpp:4
#define d
Definition: ke_i.h:81
int CDECL MSVCRT_I10_OUTPUT(_LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
Definition: i10output.c:27
_Check_return_ __MINGW_NOTHROW _CRTIMP int __cdecl _finite(_In_ double)
_STLP_DECLSPEC complex< float > _STLP_CALL log10(const complex< float > &)
Definition: complex.cpp:230
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define CDECL
Definition: compat.h:21
#define I10_OUTPUT_MAX_PREC
Definition: i10output.c:3
DWORD exp
Definition: msg.c:15681
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)