Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
6231ce59
Commit
6231ce59
authored
May 30, 2013
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix buggy double2str()
parent
57b30ad2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
17 deletions
+53
-17
class_board_item.cpp
pcbnew/class_board_item.cpp
+6
-5
kicad_plugin.cpp
pcbnew/kicad_plugin.cpp
+47
-12
No files found.
pcbnew/class_board_item.cpp
View file @
6231ce59
...
@@ -88,11 +88,9 @@ wxString BOARD_ITEM::GetLayerName() const
...
@@ -88,11 +88,9 @@ wxString BOARD_ITEM::GetLayerName() const
std
::
string
BOARD_ITEM
::
FormatInternalUnits
(
int
aValue
)
std
::
string
BOARD_ITEM
::
FormatInternalUnits
(
int
aValue
)
{
{
char
buf
[
50
];
char
buf
[
50
];
double
mm
=
aValue
/
IU_PER_MM
;
int
len
;
int
len
;
double
mm
=
aValue
/
IU_PER_MM
;
if
(
mm
!=
0.0
&&
fabs
(
mm
)
<=
0.0001
)
if
(
mm
!=
0.0
&&
fabs
(
mm
)
<=
0.0001
)
{
{
...
@@ -101,7 +99,10 @@ std::string BOARD_ITEM::FormatInternalUnits( int aValue )
...
@@ -101,7 +99,10 @@ std::string BOARD_ITEM::FormatInternalUnits( int aValue )
while
(
--
len
>
0
&&
buf
[
len
]
==
'0'
)
while
(
--
len
>
0
&&
buf
[
len
]
==
'0'
)
buf
[
len
]
=
'\0'
;
buf
[
len
]
=
'\0'
;
++
len
;
if
(
buf
[
len
]
==
'.'
)
buf
[
len
]
=
'\0'
;
else
++
len
;
}
}
else
else
{
{
...
...
pcbnew/kicad_plugin.cpp
View file @
6231ce59
...
@@ -64,27 +64,62 @@ static const wxString traceFootprintLibrary( wxT( "KicadFootprintLib" ) );
...
@@ -64,27 +64,62 @@ static const wxString traceFootprintLibrary( wxT( "KicadFootprintLib" ) );
// Helper function to print a float number without using scientific notation
// Helper function to print a float number without using scientific notation
// and no trailing 0
// and no trailing 0
// For many reasons, S-expr does not accept scientific notation
// for floating numbers, so we cannot use the %g format to print a fp number
#if 0
//
and %f leaves trailing
0.
//
Does not work for aValue < 0.0001 and >
0.
//
this helper function uses the %f format, and then removes trailing 0
//
Will need to support exponents in DSNLEXER if we get exponents > 16, i.e. the "precision".
std::string double2str( double aValue )
std::string double2str( double aValue )
{
{
char
buf
[
50
];
char
buf[50];
int
len
=
sprintf
(
buf
,
"%.16f"
,
aValue
)
;
int
len
;
while
(
--
len
>
0
&&
buf
[
len
]
==
'0'
)
if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
buf
[
len
]
=
'\0'
;
{
len = sprintf( buf, "%.10f", aValue );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( buf[len] == '.' )
buf[len--] = '\0';
// Remove useless separator:
if
(
buf
[
len
]
==
'.'
)
buf
[
len
]
=
'\0'
;
else
++len;
++len;
}
else
{
len = sprintf( buf, "%.10g", mm );
}
return std::string( buf, len );
return std::string( buf, len );
}
}
#else
// this one handles 0.00001 ok, and 1.222222222222222 ok, previous did not.
std
::
string
double2str
(
double
aValue
)
{
char
buf
[
50
];
int
len
;
if
(
aValue
!=
0.0
&&
fabs
(
aValue
)
<=
0.0001
)
{
len
=
sprintf
(
buf
,
"%.16f"
,
aValue
);
while
(
--
len
>
0
&&
buf
[
len
]
==
'0'
)
buf
[
len
]
=
'\0'
;
if
(
buf
[
len
]
==
'.'
)
buf
[
len
]
=
'\0'
;
else
++
len
;
}
else
{
len
=
sprintf
(
buf
,
"%.16g"
,
aValue
);
}
return
std
::
string
(
buf
,
len
);;
}
#endif
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment