kicad/common/dialogs
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
..
dialog_display_info_HTML_base.cpp Common dialog file housekeeping. Code cleanup, and minor fixes. 2010-11-20 11:59:59 +01:00
dialog_display_info_HTML_base.fbp Speed up DIALOG_LOAD_ERROR::ListSet(), used to display lists of errors ( up to 100 x faster) in DRC or loading lib errors 2011-06-26 18:03:26 +02:00
dialog_display_info_HTML_base.h Common dialog file housekeeping. Code cleanup, and minor fixes. 2010-11-20 11:59:59 +01:00
dialog_exit_base.cpp All: added a standard exit dialog called by int DisplayExitDialog( wxWindow* aParent, const wxString& aMessage ) 2012-03-08 18:47:23 +01:00
dialog_exit_base.fbp All: added a standard exit dialog called by int DisplayExitDialog( wxWindow* aParent, const wxString& aMessage ) 2012-03-08 18:47:23 +01:00
dialog_exit_base.h All: added a standard exit dialog called by int DisplayExitDialog( wxWindow* aParent, const wxString& aMessage ) 2012-03-08 18:47:23 +01:00
dialog_get_component.cpp Fix @JP messages (no bugs, just comment lines) 2012-02-19 20:53:11 +01:00
dialog_get_component_base.cpp Common dialog file housekeeping. Code cleanup, and minor fixes. 2010-11-20 11:59:59 +01:00
dialog_get_component_base.fbp Common dialog file housekeeping. Code cleanup, and minor fixes. 2010-11-20 11:59:59 +01:00
dialog_get_component_base.h Common dialog file housekeeping. Code cleanup, and minor fixes. 2010-11-20 11:59:59 +01:00
dialog_hotkeys_editor.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
dialog_hotkeys_editor_base.cpp Dialog escape key termination and default button fixes. 2011-03-14 15:17:42 -04:00
dialog_hotkeys_editor_base.fbp Dialog escape key termination and default button fixes. 2011-03-14 15:17:42 -04:00
dialog_hotkeys_editor_base.h Dialog escape key termination and default button fixes. 2011-03-14 15:17:42 -04:00
dialog_image_editor.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
dialog_image_editor.fbp Eeschema: bitmap editor dialog: some enhancements 2011-09-02 21:43:56 +02:00
dialog_image_editor.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
dialog_image_editor_base.cpp Eeschema: bitmap editor dialog: some enhancements 2011-09-02 21:43:56 +02:00
dialog_image_editor_base.h Eeschema: bitmap editor dialog: some enhancements 2011-09-02 21:43:56 +02:00
dialog_page_settings.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
dialog_page_settings.h Fix issues about translations: 2012-03-27 18:41:13 +02:00
dialog_page_settings_base.cpp Fix issues about translations: 2012-03-27 18:41:13 +02:00
dialog_page_settings_base.fbp Fix issues about translations: 2012-03-27 18:41:13 +02:00
dialog_page_settings_base.h Fix issues about translations: 2012-03-27 18:41:13 +02:00