kicad/cvpcb
Dick Hollenbeck c24863c078 // Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did.  This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.


#include <stdio.h>
#include <assert.h>
#include <limits.h>

//-----<KiROUND KIT>------------------------------------------------------------

/**
 * KiROUND
 * rounds a floating point number to an int using
 * "round halfway cases away from zero".
 * In Debug build an assert fires if will not fit into an int.
 */

#if defined( DEBUG )

// DEBUG: a macro to capture line and file, then calls this inline

static inline int KiRound( double v, int line, const char* filename )
{
    v = v < 0 ? v - 0.5 : v + 0.5;
    if( v > INT_MAX + 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    else if( v < INT_MIN - 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    return int( v );
}

#define KiROUND( v )    KiRound( v, __LINE__, __FILE__ )

#else

// RELEASE: a macro so compile can pre-compute constants.

#define KiROUND( v )  int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )

#endif


//-----</KiROUND KIT>-----------------------------------------------------------

// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );


int main( int argc, char** argv )
{
    for( double d = double(INT_MAX)-1;  d < double(INT_MAX)+8;  d += 2.0 )
    {
        int i = KiROUND( d );

        printf( "t: %d  %.16g\n", i, d );
    }

    return 0;
}
2012-04-19 01:55:45 -05:00
..
dialogs All: new middle mouse pan feature, from lajos kamocsay (and jp charras for some enhancements). 2012-04-11 20:54:20 +02:00
CMakeLists.txt Hit test method rationalization and other minor improvements. 2012-03-15 10:31:16 -04:00
Info.plist Minor UI changes that affect OS X, see CHANGELOG.txt 2011-05-12 20:47:56 +02:00
autosel.cpp Pcbnew and Cvpcb: more about new netlist support: see CHANGELOG (important changes). 2012-02-01 20:49:37 +01:00
cfg.cpp Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
class_DisplayFootprintsFrame.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
class_DisplayFootprintsFrame.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_components_listbox.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_footprints_listbox.cpp Joe Ferner's merge 2012-03-16 22:01:53 -05:00
common_help_msg.h Pcbnew and Cvpcb: more about new netlist support: see CHANGELOG (important changes). 2012-02-01 20:49:37 +01:00
cvframe.cpp Added a toolbar button to cvpcb to filter by pin/pad count. 2012-03-15 14:20:22 -04:00
cvpcb.cpp Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
cvpcb.h Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
cvpcb.icns Rework on icons, and more OS X updates 2010-05-09 04:04:44 +02:00
cvpcb.rc Remove old xpm icons files 2012-04-07 13:09:57 +02:00
cvpcb_doc.icns Rework on icons, and more OS X updates 2010-05-09 04:04:44 +02:00
cvpcb_id.h Added a toolbar button to cvpcb to filter by pin/pad count. 2012-03-15 14:20:22 -04:00
cvpcb_mainframe.h CvPcb: serious code cleaning. More comments. Remove useless files and some files renamed with a better name. 2012-02-11 10:04:26 +01:00
cvstruct.h Added a toolbar button to cvpcb to filter by pin/pad count. 2012-03-15 14:20:22 -04:00
listboxes.cpp Pcbnew and Cvpcb: more about new netlist support: see CHANGELOG (important changes). 2012-02-01 20:49:37 +01:00
loadcmp.cpp cvpcb LEGACY_PLUGIN usage factoring 2012-04-16 21:58:03 -05:00
menubar.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
read_write_cmpfile.cpp CvPcb: serious code cleaning. More comments. Remove useless files and some files renamed with a better name. 2012-02-11 10:04:26 +01:00
readschematicnetlist.cpp Pcbnew and Cvpcb: more about new netlist support: see CHANGELOG (important changes). 2012-02-01 20:49:37 +01:00
readwrite_dlgs.cpp Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
setvisu.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
tool_cvpcb.cpp Added a toolbar button to cvpcb to filter by pin/pad count. 2012-03-15 14:20:22 -04:00