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

This commit is contained in:
Dick Hollenbeck 2012-06-24 13:41:37 -05:00
parent 4019284e66
commit e5452a7a39
4 changed files with 53 additions and 57 deletions

View File

@ -355,12 +355,6 @@ void LEGACY_PLUGIN::loadGENERAL()
{
#if defined( USE_PCBNEW_NANOMETRES )
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
THROW_IO_ERROR( _( "May not load millimeter *.brd file into 'Pcbnew compiled for deci-mils'" ) );
#endif
@ -2567,15 +2561,12 @@ void LEGACY_PLUGIN::loadPCB_TARGET()
int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
{
long double engUnits = biuToDisk * aValue;
int len;
double engUnits = biuToDisk * aValue;
int len;
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
{
// Windows printf and sprintf do not support long double, but MinGW replaces
// snprintf and vsnprintf only with versions that do.
// http://gcc.gnu.org/ml/libstdc++/2008-02/msg00081.html
len = snprintf( buf, SPBUFZ, "%.10Lf", engUnits );
len = snprintf( buf, SPBUFZ, "%.10f", engUnits );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
@ -2584,9 +2575,16 @@ int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
}
else
{
// Windows printf and sprintf do not support long double, but MinGW replaces
// snprintf and vsnprintf only with versions that do.
len = snprintf( buf, SPBUFZ, "%.10Lg", engUnits );
// The %.10g is about optimal since we are dealing with a bounded
// range on aValue, and we can be sure that there will never
// 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;
}
@ -2636,12 +2634,7 @@ BIU LEGACY_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
errno = 0;
// The strategy in this function, which utilizes "long double" was verified using
// 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 );
double fval = strtod( aValue, &nptr );
if( errno )
{
@ -2708,20 +2701,20 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties )
// conversion factor for saving RAM BIUs to KICAD legacy file format.
#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
biuToDisk = 1.0L; // BIUs are deci-mils
biuToDisk = 1.0; // BIUs are deci-mils
#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.
// 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
// 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
// or BIUs are deci-mils
diskToBiu = IU_PER_DECIMILS; // BIUs are nanometers if defined(USE_PCBNEW_NANOMETRES)
// else are deci-mils
}
@ -3859,12 +3852,6 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
{
#if defined( USE_PCBNEW_NANOMETRES )
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
THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) );
#endif

View File

@ -126,16 +126,13 @@ protected:
int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
FPL_CACHE* m_cache;
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void init( PROPERTIES* aProperties );
// Use of long double might affect MSVC++'s ability to make KiCad.
long double biuToDisk; ///< convert from BIUs to disk engineering units
double biuToDisk; ///< convert from BIUs to disk engineering units
///< 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
/**

View File

@ -27,25 +27,23 @@ static inline int KiROUND( double v )
typedef int BIU;
#define BIU_PER_MM 1e6L
#define BIU_PER_MM 1e6
//double scale = BIU_PER_MM;
//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 )
{
long double engUnits = aValue * scale;
char temp[48];
int len;
double engUnits = aValue * scale;
char temp[48];
int len;
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
{
snprintf( temp, sizeof(temp), "%.10Lf", engUnits );
len = strlen( temp );
len = snprintf( temp, sizeof( temp ), "%.16f", engUnits );
while( --len > 0 && temp[len] == '0' )
temp[len] = '\0';
@ -54,7 +52,7 @@ std::string biuFmt( BIU aValue )
}
else
{
len = snprintf( temp, sizeof(temp), "%.10Lg", engUnits );
len = snprintf( temp, sizeof( temp ), "%.16g", engUnits );
}
return std::string( temp, len );;
@ -63,8 +61,9 @@ std::string biuFmt( BIU aValue )
int parseBIU( const char* s )
{
long double d = strtold( s, NULL );
double d = strtod( s, NULL );
return KiROUND( double( d * BIU_PER_MM ) );
// return int( d * BIU_PER_MM );
}
@ -84,7 +83,7 @@ int main( int argc, char** argv )
printf( "%s: s:%s\n", __func__, s.c_str() );
exit(1);
exit(0);
}
// printf( "sizeof(long double): %zd\n", sizeof( long double ) );

View File

@ -99,6 +99,9 @@ indent_class = true # false/true
# Whether to indent the stuff after a leading class colon
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
indent_ctor_init = 0 # number
@ -199,7 +202,7 @@ indent_comma_paren = false # false/true
indent_bool_paren = false # false/true
# If 'indent_bool_paren' is true, controls the indent of the first expression. If TRUE, aligns the first expression to the following ones
indent_first_bool_expr = true # false/true
indent_first_bool_expr = true # false/true
# If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended)
indent_square_nl = false # false/true
@ -221,6 +224,12 @@ sp_arith = force # ignore/add/remove/force
# Add or remove space around assignment operator '=', '+=', etc
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
sp_assign_default = 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
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'
sp_before_sparen = remove # ignore/add/remove/force
@ -580,7 +593,7 @@ sp_before_send_oc_colon = ignore # ignore/add/remove/force
# Add or remove space after the (type) in message specs
# '-(int)f: (int) x;' vs '-(int)f: (int)x;'
sp_after_oc_type = add # ignore/add/remove/force
sp_after_oc_type = add # ignore/add/remove/force
# Add or remove space after the first (type) in message specs
# '-(int) f:(int)x;' vs '-(int)f:(int)x;'
@ -621,10 +634,10 @@ sp_case_label = force # ignore/add/remove/force
sp_range = ignore # ignore/add/remove/force
# Control the space after the opening of a C++ comment '// A' vs '//A'
sp_cmt_cpp_start = force # ignore/add/remove/force
sp_cmt_cpp_start = force # ignore/add/remove/force
# Controls the spaces between #else or #endif and a trailing comment
sp_endif_cmt = force # ignore/add/remove/force
sp_endif_cmt = force # ignore/add/remove/force
# Controls the spaces after 'new', 'delete', and 'delete[]'
sp_after_new = force # ignore/add/remove/force
@ -1076,10 +1089,10 @@ nl_define_macro = false # false/true
nl_squeeze_ifdef = false # false/true
# Add or remove blank line before 'if'
nl_before_if = add # ignore/add/remove/force
nl_before_if = add # ignore/add/remove/force
# Add or remove blank line after 'if' statement
nl_after_if = add # ignore/add/remove/force
nl_after_if = add # ignore/add/remove/force
# Add or remove blank line before 'for'
nl_before_for = add # ignore/add/remove/force