ReactOS 0.4.15-dev-8408-g466a198
num_put_float.cpp File Reference
#include "stlport_prefix.h"
#include <cmath>
#include <ios>
#include <locale>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
Include dependency graph for num_put_float.cpp:

Go to the source code of this file.

Classes

struct  _Dig< N >
 
struct  _Dig< 0 >
 
struct  GroupPos
 

Macros

#define NDIG   82
 
#define todigit(x)   ((x)+'0')
 
#define MAXEDIGITS   int(_Dig<LDBL_MAX_10_EXP>::dig)
 
#define MAXFSIG   LDBL_DIG
 
#define MAXFCVT   (LDBL_DIG + 1)
 
#define USE_SPRINTF_INSTEAD
 

Functions

static void __fill_fmtbuf (char *fmtbuf, ios_base::fmtflags flags, char long_modifier)
 
template<class _FloatT >
static size_t __write_floatT (__iostring &buf, ios_base::fmtflags flags, int precision, _FloatT x, char modifier)
 
size_t _STLP_CALL __write_float (__iostring &buf, ios_base::fmtflags flags, int precision, double x)
 
size_t _STLP_CALL __write_float (__iostring &buf, ios_base::fmtflags flags, int precision, long double x)
 
void _STLP_CALL __get_floor_digits (__iostring &out, _STLP_LONGEST_FLOAT_TYPE __x)
 
void _STLP_CALL __convert_float_buffer (__iostring const &str, __iowstring &out, const ctype< wchar_t > &ct, wchar_t dot, bool __check_dot)
 
void _STLP_CALL __adjust_float_buffer (__iostring &str, char dot)
 

Macro Definition Documentation

◆ MAXEDIGITS

#define MAXEDIGITS   int(_Dig<LDBL_MAX_10_EXP>::dig)

Definition at line 116 of file num_put_float.cpp.

◆ MAXFCVT

#define MAXFCVT   (LDBL_DIG + 1)

Definition at line 118 of file num_put_float.cpp.

◆ MAXFSIG

#define MAXFSIG   LDBL_DIG

Definition at line 117 of file num_put_float.cpp.

◆ NDIG

#define NDIG   82

Definition at line 28 of file num_put_float.cpp.

◆ todigit

#define todigit (   x)    ((x)+'0')

Definition at line 31 of file num_put_float.cpp.

◆ USE_SPRINTF_INSTEAD

#define USE_SPRINTF_INSTEAD

Definition at line 206 of file num_put_float.cpp.

Function Documentation

◆ __adjust_float_buffer()

void _STLP_CALL __adjust_float_buffer ( __iostring str,
char  dot 
)

Definition at line 904 of file num_put_float.cpp.

904 {
905 if ('.' != dot) {
906 size_t __dot_pos = str.find('.');
907 if (__dot_pos != string::npos) {
908 str[__dot_pos] = dot;
909 }
910 }
911}
const WCHAR * str

◆ __convert_float_buffer()

void _STLP_CALL __convert_float_buffer ( __iostring const str,
__iowstring out,
const ctype< wchar_t > &  ct,
wchar_t  dot,
bool  __check_dot 
)

Definition at line 873 of file num_put_float.cpp.

874 {
875 string::const_iterator str_ite(str.begin()), str_end(str.end());
876
877 //First loop, check the dot char
878 if (__check_dot) {
879 while (str_ite != str_end) {
880 if (*str_ite != '.') {
881 out += ct.widen(*str_ite++);
882 } else {
883 out += dot;
884 break;
885 }
886 }
887 } else {
888 if (str_ite != str_end) {
889 out += ct.widen(*str_ite);
890 }
891 }
892
893 if (str_ite != str_end) {
894 //Second loop, dot has been found, no check anymore
895 while (++str_ite != str_end) {
896 out += ct.widen(*str_ite);
897 }
898 }
899}
wchar_t widen(char __c) const
Definition: _ctype.h:206
static FILE * out
Definition: regtests2xml.c:44

Referenced by __get_money_digits_aux(), and __put_float().

◆ __fill_fmtbuf()

static void __fill_fmtbuf ( char fmtbuf,
ios_base::fmtflags  flags,
char  long_modifier 
)
static

Definition at line 709 of file num_put_float.cpp.

709 {
710 fmtbuf[0] = '%';
711 int i = 1;
712
713 if (flags & ios_base::showpos)
714 fmtbuf[i++] = '+';
715
716 if (flags & ios_base::showpoint)
717 fmtbuf[i++] = '#';
718
719 fmtbuf[i++] = '.';
720 fmtbuf[i++] = '*';
721
722 if (long_modifier)
723 fmtbuf[i++] = long_modifier;
724
725 switch (flags & ios_base::floatfield)
726 {
727 case ios_base::scientific:
728 fmtbuf[i++] = (flags & ios_base::uppercase) ? 'E' : 'e';
729 break;
730 case ios_base::fixed:
731# if defined (__FreeBSD__)
732 fmtbuf[i++] = 'f';
733# else
734 fmtbuf[i++] = (flags & ios_base::uppercase) ? 'F' : 'f';
735# endif
736 break;
737 default:
738 fmtbuf[i++] = (flags & ios_base::uppercase) ? 'G' : 'g';
739 break;
740 }
741
742 fmtbuf[i] = 0;
743}
GLbitfield flags
Definition: glext.h:7161
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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by __write_floatT().

◆ __get_floor_digits()

void _STLP_CALL __get_floor_digits ( __iostring out,
_STLP_LONGEST_FLOAT_TYPE  __x 
)

Definition at line 843 of file num_put_float.cpp.

843 {
845#if defined (USE_SPRINTF_INSTEAD)
846 char cvtbuf[limits::max_exponent10 + 6];
847# if !defined (_STLP_NO_LONG_DOUBLE)
848 snprintf(_STLP_ARRAY_AND_SIZE(cvtbuf), "%Lf", __x); // check for 1234.56!
849# else
850 snprintf(_STLP_ARRAY_AND_SIZE(cvtbuf), "%f", __x); // check for 1234.56!
851# endif
852 char *p = strchr( cvtbuf, '.' );
853 if ( p == 0 ) {
854 out.append( cvtbuf );
855 } else {
856 out.append( cvtbuf, p );
857 }
858#else
859 char cvtbuf[limits::max_exponent10 + 1];
860 char * bp;
861 int decpt, sign;
862 bp = _Stl_fcvtR(__x, 0, &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf));
863
864 if (sign) {
865 out += '-';
866 }
867 out.append(bp, bp + decpt);
868#endif
869}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define _STLP_ARRAY_AND_SIZE(A)
Definition: features.h:1054
GLfloat GLfloat p
Definition: glext.h:8902
#define sign(x)
Definition: mapdesc.cc:613
static size_t double int int * decpt
Definition: printf.c:72
#define snprintf
Definition: wintirpc.h:48

Referenced by __get_money_digits_aux().

◆ __write_float() [1/2]

size_t _STLP_CALL __write_float ( __iostring buf,
ios_base::fmtflags  flags,
int  precision,
double  x 
)

Definition at line 822 of file num_put_float.cpp.

823 {
825#if defined (USE_SPRINTF_INSTEAD)
826 , 0
827#endif
828 );
829}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLint GLint * precision
Definition: glext.h:7539
#define USE_SPRINTF_INSTEAD
static size_t __write_floatT(__iostring &buf, ios_base::fmtflags flags, int precision, _FloatT x, char modifier)

Referenced by __do_put_float().

◆ __write_float() [2/2]

size_t _STLP_CALL __write_float ( __iostring buf,
ios_base::fmtflags  flags,
int  precision,
long double  x 
)

Definition at line 833 of file num_put_float.cpp.

834 {
836#if defined (USE_SPRINTF_INSTEAD)
837 , 'L'
838#endif
839 );
840}

◆ __write_floatT()

template<class _FloatT >
static size_t __write_floatT ( __iostring buf,
ios_base::fmtflags  flags,
int  precision,
_FloatT  x,
char  modifier 
)
static

Definition at line 748 of file num_put_float.cpp.

751 {
752 /* In theory, if we want 'arbitrary' precision, we should use 'arbitrary'
753 * buffer size below, but really we limited by exponent part in double.
754 * - ptr
755 */
756 typedef numeric_limits<_FloatT> limits;
757 char static_buf[limits::max_exponent10 + 6]; // 6: -xxx.yyyE-zzz (sign, dot, E, exp sign, \0)
758 char fmtbuf[32];
759 __fill_fmtbuf(fmtbuf, flags, modifier);
760 snprintf(_STLP_ARRAY_AND_SIZE(static_buf), fmtbuf, precision, x);
761 buf = static_buf;
762 return find_if(buf.begin(), buf.end(), GroupPos()) - buf.begin();
763#else
764 ) {
765 typedef numeric_limits<_FloatT> limits;
766 //If numeric_limits support is correct we use the exposed values to detect NaN and infinity:
767 if (limits::has_infinity && limits::has_quiet_NaN) {
768 if (!(x == x) || // NaN check
769 (x == limits::infinity() || x == -limits::infinity())) {
770 return __format_nan_or_inf(buf, x, flags);
771 }
772 }
773 // numeric_limits support is not good enough, we rely on platform dependent function
774 // _Stl_is_nan_or_inf that do not support long double.
775 else if (_Stl_is_nan_or_inf(x)) {
776 return __format_nan_or_inf(buf, x, flags);
777 }
778# if defined (__MINGW32__)
779 //For the moment MinGW is limited to display at most numeric_limits<double>::max()
782 return __format_nan_or_inf(buf, x, flags);
783 }
784# endif
785
786 /* Buffer size is max number of digits which is the addition of:
787 * - max_exponent10: max number of digits in fixed mode
788 * - digits10 + 2: max number of significant digits
789 * - trailing '\0'
790 */
791 char cvtbuf[limits::max_exponent10 + limits::digits10 + 2 + 1];
792 char *bp;
793 int decpt, sign;
794
795 switch (flags & ios_base::floatfield) {
796 case ios_base::fixed:
797 {
798 /* Here, number of digits represents digits _after_ decimal point.
799 * In order to limit static buffer size we have to give 2 different values depending on x value.
800 * For small values (abs(x) < 1) we need as many digits as requested by precision limited by the maximum number of digits
801 * which is min_exponent10 + digits10 + 2
802 * For bigger values we won't have more than limits::digits10 + 2 digits after decimal point. */
803 int digits10 = (x > -1.0 && x < 1.0 ? -limits::min_exponent10 + limits::digits10 + 2
804 : limits::digits10 + 2);
805 bp = _Stl_fcvtR(x, (min) (precision, digits10), &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf) );
806 }
807 break;
808 case ios_base::scientific:
809 default:
810 /* Here, number of digits is total number of digits which is limited to digits10 + 2. */
811 {
812 int digits10 = limits::digits10 + 2;
813 bp = _Stl_ecvtR(x, (min) (precision, digits10), &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf) );
814 }
815 break;
816 }
817 return __format_float(buf, bp, decpt, sign, x == 0.0, flags, precision);
818#endif
819}
_STLP_MOVE_TO_STD_NAMESPACE _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred)
Definition: _algobase.c:214
#define min(a, b)
Definition: monoChain.cc:55
static void __fill_fmtbuf(char *fmtbuf, ios_base::fmtflags flags, char long_modifier)

Referenced by __write_float().