ReactOS  0.4.15-dev-2700-g4b4ffa9
i10output.c File Reference
#include <precomp.h>
Include dependency graph for i10output.c:

Go to the source code of this file.

Classes

struct  _I10_OUTPUT_DATA
 

Macros

#define I10_OUTPUT_MAX_PREC   21
 

Functions

int CDECL MSVCRT_I10_OUTPUT (_LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
 

Macro Definition Documentation

◆ I10_OUTPUT_MAX_PREC

#define I10_OUTPUT_MAX_PREC   21

Definition at line 3 of file i10output.c.

Function Documentation

◆ MSVCRT_I10_OUTPUT()

int CDECL MSVCRT_I10_OUTPUT ( _LDOUBLE  ld80,
int  prec,
int  flag,
struct _I10_OUTPUT_DATA data 
)

Definition at line 27 of file i10output.c.

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_s(format, sizeof(format), "%%.%dle", prec);
84  sprintf_s(buf, sizeof(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 }
_Check_return_ __MINGW_NOTHROW _CRTIMP int __cdecl _isnan(_In_ double)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static jsstr_t * nan_str
Definition: jsstr.c:281
#define TRACE(s)
Definition: solgame.cpp:4
_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
#define I10_OUTPUT_MAX_PREC
Definition: i10output.c:3
DWORD exp
Definition: msg.c:16033
_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)
#define d
Definition: ke_i.h:81