FieldConvertors.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2001-2014
3 **
4 ** This file is part of the QuickFIX FIX Engine
5 **
6 ** This file may be distributed under the terms of the quickfixengine.org
7 ** license as defined by quickfixengine.org and appearing in the file
8 ** LICENSE included in the packaging of this file.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 ** See http://www.quickfixengine.org/LICENSE for licensing information.
14 **
15 ** Contact ask@quickfixengine.org if any conditions of this licensing are
16 ** not clear to you.
17 **
18 ****************************************************************************/
19 
20 #ifdef _MSC_VER
21 #include "stdafx.h"
22 #else
23 #include "config.h"
24 #endif
25 
26 #include <math.h>
27 #include "FieldConvertors.h"
28 #include <math.h>
29 
30 namespace FIX
31 {
32 
33 // we include "double-conversion" project in FIX namespace
34 // to avoid linking errors if quickfix is linked statically
35 // and "double-conversion" is already used by target project
36 
37 #include "double-conversion/diy-fp.cc"
38 #include "double-conversion/fixed-dtoa.cc"
39 #include "double-conversion/bignum.cc"
40 #include "double-conversion/bignum-dtoa.cc"
41 #include "double-conversion/cached-powers.cc"
42 #include "double-conversion/fast-dtoa.cc"
43 #include "double-conversion/strtod.cc"
44 #include "double-conversion/double-conversion.cc"
45 
46  static double_conversion::DoubleToStringConverter g_dtoa_converter(
47  double_conversion::DoubleToStringConverter::NO_FLAGS,
48  "INF",
49  "NAN",
50  'e',
54  0);
55 
56  static double_conversion::StringToDoubleConverter g_atod_converter(
57  double_conversion::StringToDoubleConverter::NO_FLAGS,
58  std::numeric_limits<double>::quiet_NaN(),
59  std::numeric_limits<double>::quiet_NaN(),
60  "INF",
61  "NAN");
62 
63  double DoubleConvertor::fast_strtod( const char * buffer, int size, int * processed_chars )
64  {
65  return g_atod_converter.StringToDouble( buffer, size, processed_chars );
66  }
67 
68  int DoubleConvertor::fast_dtoa( char * buffer, int size, double value )
69  {
70  double_conversion::StringBuilder builder( buffer, size );
71  if( !g_dtoa_converter.ToPrecision( value, DoubleConvertor::SIGNIFICANT_DIGITS, &builder ) )
72  {
73  builder.Reset();
74  return 0;
75  }
76 
77  builder.TrimTrailingZeros();
78  return builder.position();
79  }
80 
81  int DoubleConvertor::fast_fixed_dtoa( char * buffer, int size, double value )
82  {
83  double_conversion::StringBuilder builder( buffer, size );
84  if( !g_dtoa_converter.ToFixed( value, DoubleConvertor::SIGNIFICANT_DIGITS, &builder ) )
85  {
86  builder.Reset();
87  return 0;
88  }
89 
90  return builder.position();
91  }
92 
93 }
FIX::g_dtoa_converter
static double_conversion::DoubleToStringConverter g_dtoa_converter(double_conversion::DoubleToStringConverter::NO_FLAGS, "INF", "NAN", 'e', -DoubleConvertor::SIGNIFICANT_DIGITS, DoubleConvertor::SIGNIFICANT_DIGITS, DoubleConvertor::SIGNIFICANT_DIGITS - 1, 0)
FieldConvertors.h
FIX::DoubleConvertor::fast_dtoa
static int fast_dtoa(char *buffer, int size, double value)
Definition: FieldConvertors.cpp:68
FIX
Definition: Acceptor.cpp:34
FIX::DoubleConvertor::fast_strtod
static double fast_strtod(const char *buffer, int size, int *processed_chars)
Definition: FieldConvertors.cpp:63
FIX::DoubleConvertor::SIGNIFICANT_DIGITS
static const int SIGNIFICANT_DIGITS
Definition: FieldConvertors.h:269
FIX::g_atod_converter
static double_conversion::StringToDoubleConverter g_atod_converter(double_conversion::StringToDoubleConverter::NO_FLAGS, std::numeric_limits< double >::quiet_NaN(), std::numeric_limits< double >::quiet_NaN(), "INF", "NAN")
FIX::DoubleConvertor::fast_fixed_dtoa
static int fast_fixed_dtoa(char *buffer, int size, double value)
Definition: FieldConvertors.cpp:81

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001