Commit e5452a7a authored by Dick Hollenbeck's avatar Dick Hollenbeck

remove "long double" dependency, mingw was falling over when using it.

parent 4019284e
...@@ -355,12 +355,6 @@ void LEGACY_PLUGIN::loadGENERAL() ...@@ -355,12 +355,6 @@ void LEGACY_PLUGIN::loadGENERAL()
{ {
#if defined( USE_PCBNEW_NANOMETRES ) #if defined( USE_PCBNEW_NANOMETRES )
diskToBiu = IU_PER_MM; diskToBiu = IU_PER_MM;
#elif defined(DEBUG)
// mm to deci-mils:
// advanced testing of round tripping only, not supported in non DEBUG build
diskToBiu = IU_PER_MM;
#else #else
THROW_IO_ERROR( _( "May not load millimeter *.brd file into 'Pcbnew compiled for deci-mils'" ) ); THROW_IO_ERROR( _( "May not load millimeter *.brd file into 'Pcbnew compiled for deci-mils'" ) );
#endif #endif
...@@ -2567,15 +2561,12 @@ void LEGACY_PLUGIN::loadPCB_TARGET() ...@@ -2567,15 +2561,12 @@ void LEGACY_PLUGIN::loadPCB_TARGET()
int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
{ {
long double engUnits = biuToDisk * aValue; double engUnits = biuToDisk * aValue;
int len; int len;
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
{ {
// Windows printf and sprintf do not support long double, but MinGW replaces len = snprintf( buf, SPBUFZ, "%.10f", engUnits );
// snprintf and vsnprintf only with versions that do.
// http://gcc.gnu.org/ml/libstdc++/2008-02/msg00081.html
len = snprintf( buf, SPBUFZ, "%.10Lf", engUnits );
while( --len > 0 && buf[len] == '0' ) while( --len > 0 && buf[len] == '0' )
buf[len] = '\0'; buf[len] = '\0';
...@@ -2584,9 +2575,16 @@ int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const ...@@ -2584,9 +2575,16 @@ int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
} }
else else
{ {
// Windows printf and sprintf do not support long double, but MinGW replaces // The %.10g is about optimal since we are dealing with a bounded
// snprintf and vsnprintf only with versions that do. // range on aValue, and we can be sure that there will never
len = snprintf( buf, SPBUFZ, "%.10Lg", engUnits ); // be a reason to have more than 6 digits to the right of the
// decimal point because we are converting from integer
// (signed whole numbers) nanometers to mm. A value of
// 0.000001 is one nanometer, the smallest positive nonzero value
// that we can ever have here. If you ever see a board file with
// more digits to the right of the decimal point than 6, this is a
// possibly a bug in a formatting string nearby.
len = snprintf( buf, SPBUFZ, "%.10g", engUnits );
} }
return len; return len;
} }
...@@ -2636,12 +2634,7 @@ BIU LEGACY_PLUGIN::biuParse( const char* aValue, const char** nptrptr ) ...@@ -2636,12 +2634,7 @@ BIU LEGACY_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
errno = 0; errno = 0;
// The strategy in this function, which utilizes "long double" was verified using double fval = strtod( aValue, &nptr );
// tools/test-nm-biu-to-ascii-mm-round-tripping.cpp. For it to work "long double" must
// have more precision than double. gcc has this, and its all we care about.
// MINGW does have a working strtold()
long double fval = strtold( aValue, &nptr );
if( errno ) if( errno )
{ {
...@@ -2708,20 +2701,20 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) ...@@ -2708,20 +2701,20 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties )
// conversion factor for saving RAM BIUs to KICAD legacy file format. // conversion factor for saving RAM BIUs to KICAD legacy file format.
#if defined( USE_PCBNEW_NANOMETRES ) #if defined( USE_PCBNEW_NANOMETRES )
biuToDisk = 1.0L/IU_PER_MM; // BIUs are nanometers & file is mm biuToDisk = 1.0/IU_PER_MM; // BIUs are nanometers & file is mm
#else #else
biuToDisk = 1.0L; // BIUs are deci-mils biuToDisk = 1.0; // BIUs are deci-mils
#endif #endif
// conversion factor for loading KICAD legacy file format into BIUs in RAM // Conversion factor for loading KICAD legacy file format into BIUs in RAM
// Start by assuming the *.brd file is in deci-mils. // Start by assuming the *.brd file is in deci-mils.
// if we see "Units mm" in the $GENERAL section, set diskToBiu to 1000000.0 // If we see "Units mm" in the $GENERAL section, set diskToBiu to 1000000.0
// then, during the file loading process, to start a conversion from // then, during the file loading process, to start a conversion from
// mm to nanometers. // mm to nanometers. The deci-mil legacy files have no such "Units" marker
// so we must assume the file is in deci-mils until told otherwise.
diskToBiu = IU_PER_DECIMILS; // BIUs are nanometers if USE_PCBNEW_NANOMETRES diskToBiu = IU_PER_DECIMILS; // BIUs are nanometers if defined(USE_PCBNEW_NANOMETRES)
// or BIUs are deci-mils // else are deci-mils
} }
...@@ -3859,12 +3852,6 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader ) ...@@ -3859,12 +3852,6 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
{ {
#if defined( USE_PCBNEW_NANOMETRES ) #if defined( USE_PCBNEW_NANOMETRES )
m_owner->diskToBiu = IU_PER_MM; m_owner->diskToBiu = IU_PER_MM;
#elif defined(DEBUG)
// mm to deci-mils:
// advanced testing of round tripping only, not supported in non DEBUG build
m_owner->diskToBiu = IU_PER_MM;
#else #else
THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) ); THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) );
#endif #endif
......
...@@ -126,16 +126,13 @@ protected: ...@@ -126,16 +126,13 @@ protected:
int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing? int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
FPL_CACHE* m_cache; FPL_CACHE* m_cache;
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void init( PROPERTIES* aProperties ); void init( PROPERTIES* aProperties );
// Use of long double might affect MSVC++'s ability to make KiCad. double biuToDisk; ///< convert from BIUs to disk engineering units
long double biuToDisk; ///< convert from BIUs to disk engineering units
///< with this scale factor ///< with this scale factor
long double diskToBiu; ///< convert from disk engineering units to BIUs double diskToBiu; ///< convert from disk engineering units to BIUs
///< with this scale factor ///< with this scale factor
/** /**
......
...@@ -27,25 +27,23 @@ static inline int KiROUND( double v ) ...@@ -27,25 +27,23 @@ static inline int KiROUND( double v )
typedef int BIU; typedef int BIU;
#define BIU_PER_MM 1e6L #define BIU_PER_MM 1e6
//double scale = BIU_PER_MM; //double scale = BIU_PER_MM;
//double scale = UM_PER_BIU; //double scale = UM_PER_BIU;
long double scale = 1.0L/BIU_PER_MM; double scale = 1.0/BIU_PER_MM;
std::string biuFmt( BIU aValue ) std::string biuFmt( BIU aValue )
{ {
long double engUnits = aValue * scale; double engUnits = aValue * scale;
char temp[48]; char temp[48];
int len; int len;
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
{ {
snprintf( temp, sizeof(temp), "%.10Lf", engUnits ); len = snprintf( temp, sizeof( temp ), "%.16f", engUnits );
len = strlen( temp );
while( --len > 0 && temp[len] == '0' ) while( --len > 0 && temp[len] == '0' )
temp[len] = '\0'; temp[len] = '\0';
...@@ -54,7 +52,7 @@ std::string biuFmt( BIU aValue ) ...@@ -54,7 +52,7 @@ std::string biuFmt( BIU aValue )
} }
else else
{ {
len = snprintf( temp, sizeof(temp), "%.10Lg", engUnits ); len = snprintf( temp, sizeof( temp ), "%.16g", engUnits );
} }
return std::string( temp, len );; return std::string( temp, len );;
...@@ -63,8 +61,9 @@ std::string biuFmt( BIU aValue ) ...@@ -63,8 +61,9 @@ std::string biuFmt( BIU aValue )
int parseBIU( const char* s ) int parseBIU( const char* s )
{ {
long double d = strtold( s, NULL ); double d = strtod( s, NULL );
return KiROUND( double( d * BIU_PER_MM ) ); return KiROUND( double( d * BIU_PER_MM ) );
// return int( d * BIU_PER_MM );
} }
...@@ -84,7 +83,7 @@ int main( int argc, char** argv ) ...@@ -84,7 +83,7 @@ int main( int argc, char** argv )
printf( "%s: s:%s\n", __func__, s.c_str() ); printf( "%s: s:%s\n", __func__, s.c_str() );
exit(1); exit(0);
} }
// printf( "sizeof(long double): %zd\n", sizeof( long double ) ); // printf( "sizeof(long double): %zd\n", sizeof( long double ) );
......
...@@ -99,6 +99,9 @@ indent_class = true # false/true ...@@ -99,6 +99,9 @@ indent_class = true # false/true
# Whether to indent the stuff after a leading class colon # Whether to indent the stuff after a leading class colon
indent_class_colon = false # false/true indent_class_colon = false # false/true
# Virtual indent from the ':' for member initializers. Default is 2
indent_ctor_init_leading = 2 # number
# Additional indenting for constructor initializer list # Additional indenting for constructor initializer list
indent_ctor_init = 0 # number indent_ctor_init = 0 # number
...@@ -221,6 +224,12 @@ sp_arith = force # ignore/add/remove/force ...@@ -221,6 +224,12 @@ sp_arith = force # ignore/add/remove/force
# Add or remove space around assignment operator '=', '+=', etc # Add or remove space around assignment operator '=', '+=', etc
sp_assign = force # ignore/add/remove/force sp_assign = force # ignore/add/remove/force
# Add or remove space around '=' in C++11 lambda capture specifications. Overrides sp_assign
sp_cpp_lambda_assign = ignore # ignore/add/remove/force
# Add or remove space after the capture specification in C++11 lambda.
sp_cpp_lambda_paren = ignore # ignore/add/remove/force
# Add or remove space around assignment operator '=' in a prototype # Add or remove space around assignment operator '=' in a prototype
sp_assign_default = ignore # ignore/add/remove/force sp_assign_default = ignore # ignore/add/remove/force
...@@ -326,6 +335,10 @@ sp_angle_word = ignore # ignore/add/remove/force ...@@ -326,6 +335,10 @@ sp_angle_word = ignore # ignore/add/remove/force
# Add or remove space between '>' and '>' in '>>' (template stuff C++/C# only). Default=Add # Add or remove space between '>' and '>' in '>>' (template stuff C++/C# only). Default=Add
sp_angle_shift = add # ignore/add/remove/force sp_angle_shift = add # ignore/add/remove/force
# Permit removal of the space between '>>' in 'foo<bar<int> >' (C++11 only). Default=False
# sp_angle_shift cannot remove the space without this option.
sp_permit_cpp11_shift = false # false/true
# Add or remove space before '(' of 'if', 'for', 'switch', and 'while' # Add or remove space before '(' of 'if', 'for', 'switch', and 'while'
sp_before_sparen = remove # ignore/add/remove/force sp_before_sparen = remove # ignore/add/remove/force
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment