kicad/eeschema
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 LEGACY_PLUGIN is now in full use: 2012-04-16 22:12:53 -05:00
plugins All : modify macro FROM_UTF8, to ensure compatibility with files using a non utf8 encoding (old files created under Window, having some non ASCII characters). 2011-03-02 12:03:06 +01:00
CMakeLists.txt More internal unit improvements. 2012-04-13 14:51:24 -04:00
Info.plist Fix some minor OS X issues 2011-08-30 09:35:40 +02:00
annotate.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
backanno.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
block.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
block_libedit.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
build_BOM.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
bus-wire-junction.cpp Eeschema: fix a bug in bool SCH_LINE::MergeOverlap( SCH_LINE* aLine ): ends point of resulting segment incorrects. 2012-03-19 08:48:29 +01:00
busentry.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_drc_erc_item.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_libentry.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_libentry.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_library.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_library.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_netlist_object.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_netlist_object.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
cmp_library.keywords *.lst -> *.keywords, rename input filenames to CMake script TokenList2DsnLexer.cmake 2010-06-18 11:12:15 -05:00
cmp_library_lexer.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
component_references_lister.cpp Eeschema: BOM list generation: some fixes and enhancements. 2012-04-13 20:44:02 +02:00
controle.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
cross-probing.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
dangling_ends.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
database.cpp switch to C++'s false and true from C's FALSE and TRUE 2012-01-22 11:20:22 -06:00
dialog_erc_listbox.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
edit_bitmap.cpp Hit test method rationalization and other minor improvements. 2012-03-15 10:31:16 -04:00
edit_component_in_schematic.cpp Eeschema: Add better dialog to edit an existing field of the current edited component. 2012-02-22 15:04:48 +01:00
edit_label.cpp Eeschema object list and other minor improvements. 2012-02-26 13:39:39 -05:00
eelibs_read_libraryfiles.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
eeredraw.cpp Pcbnew nanometer internal unit fixes. 2012-04-15 21:25:26 -04:00
eeschema.cpp Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
eeschema.icns Rework on icons, and more OS X updates 2010-05-09 04:04:44 +02:00
eeschema.rc Remove old xpm icons files 2012-04-07 13:09:57 +02:00
eeschema_config.cpp All: new middle mouse pan feature, from lajos kamocsay (and jp charras for some enhancements). 2012-04-11 20:54:20 +02:00
eeschema_config.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
eeschema_doc.icns Updates for OS X 2010-05-16 20:18:38 +02:00
eeschema_id.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
erc.cpp Eeschema object list and other minor improvements. 2012-02-26 13:39:39 -05:00
erc.h Eeschema ERC improvements and other minor fixes. 2011-10-07 10:41:30 -04:00
events_called_functions_for_edit.cpp Fix eeschema component drawing issue during copy. Add hotkey for block save. 2012-02-23 01:35:26 +02:00
files-io.cpp Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
find.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
general.h Remove g_PcbPlotOptions, use wxformbuilder to subclass DIALOG_SHIM on several dialogs 2012-04-05 13:27:56 -05:00
getpart.cpp Eeschema: minor fixes: 2012-03-12 11:04:40 +01:00
help_common_strings.h Eeschema: fix bug #919636 2012-01-21 16:02:49 +01:00
hierarch.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
hotkeys.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
hotkeys.h Fix eeschema component drawing issue during copy. Add hotkey for block save. 2012-02-23 01:35:26 +02:00
lib_arc.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
lib_arc.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_bezier.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
lib_bezier.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_circle.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
lib_circle.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_collectors.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
lib_collectors.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
lib_draw_item.cpp Minor Eeschema LIB_ITEM object improvements. 2012-02-27 18:02:08 -05:00
lib_draw_item.h Initial Pcbnew s-expression file format commit. 2012-04-01 16:51:56 -04:00
lib_export.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
lib_field.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
lib_field.h Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
lib_pin.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
lib_pin.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_polyline.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
lib_polyline.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_rectangle.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
lib_rectangle.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
lib_text.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
lib_text.h Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
libarch.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
libedit.cpp Libedit: fix bug (svg export does not work) 2012-03-06 15:08:59 +01:00
libedit_onleftclick.cpp Libedit: Add better dialog to edit an existing field of the current edited component. 2012-02-21 18:47:30 +01:00
libedit_onrightclick.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
libedit_plot_component.cpp Libedit: fix bug (svg export does not work) 2012-03-06 15:08:59 +01:00
libedit_undo_redo.cpp Undo redo change and code cleanup. 2012-02-05 14:02:46 +01:00
libeditframe.cpp work on footprint plugin API 2012-04-15 22:18:41 -05:00
libeditframe.h Libedit: fix bug (svg export does not work) 2012-03-06 15:08:59 +01:00
libfield.cpp Eeschema: Add better dialog to edit an existing field of the current edited component. 2012-02-22 15:04:48 +01:00
load_one_schematic_file.cpp Fix issues about translations: 2012-03-27 18:41:13 +02: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
menubar_libedit.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
netform.cpp Pcbnew: First draft to use a new netlist format ( containing the same info as the intermediate netlist, but using S expressions) 2012-01-26 10:37:36 +01:00
netlist.cpp Pcbnew: Added: modview. This footprint viewer frame which has the same purpose as Viewlib in Eeschema. 2012-02-09 21:33:38 +01:00
netlist.h Eeschema: BOM list generation: some fixes and enhancements. 2012-04-13 20:44:02 +02:00
netlist_control.cpp Eeschema: minor fixes: 2012-03-12 11:04:40 +01:00
netlist_control.h Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
onleftclick.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
onrightclick.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
operations_on_items_lists.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
pinedit.cpp More internal unit improvements. 2012-04-16 13:39:32 -04:00
protos.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_base_frame.cpp More internal unit improvements. 2012-04-13 14:51:24 -04:00
sch_bitmap.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_bitmap.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_bus_entry.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
sch_bus_entry.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_collectors.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
sch_collectors.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
sch_component.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_component.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_field.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_field.h Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
sch_junction.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_junction.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_line.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
sch_line.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_marker.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_marker.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_no_connect.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_no_connect.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_polyline.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_polyline.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_screen.cpp Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
sch_sheet.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
sch_sheet.h Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
sch_sheet_path.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
sch_sheet_path.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
sch_sheet_pin.cpp Minor code and Doxygen comment improvements. 2012-03-17 10:39:27 -04:00
sch_text.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
sch_text.h Internal unit improvements and Pcbnew s-expression file format changes. 2012-04-12 17:31:31 -04:00
schedit.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
schematic_undo_redo.cpp Hit test method rationalization and other minor improvements. 2012-03-15 10:31:16 -04:00
schframe.cpp Pcbnew nanometer internal unit fixes. 2012-04-15 21:25:26 -04:00
selpart.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
sheet.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
sheetlab.cpp More internal unit improvements. 2012-04-16 13:39:32 -04:00
symbdraw.cpp More internal unit improvements. 2012-04-16 13:39:32 -04:00
symbedit.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
template_fieldnames.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
template_fieldnames.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
template_fieldnames.keywords *.lst -> *.keywords, rename input filenames to CMake script TokenList2DsnLexer.cmake 2010-06-18 11:12:15 -05:00
tool_lib.cpp Update some icons with new icons from Fabrizio Tappero. 2012-03-20 15:17:58 +01:00
tool_sch.cpp Update some icons with new icons from Fabrizio Tappero. 2012-03-20 15:17:58 +01:00
tool_viewlib.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
transform.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
transform.h Application name capitalization fixes. 2011-09-30 14:15:37 -04:00
viewlib_frame.cpp Fix @JP messages (no bugs, just comment lines) 2012-02-19 20:53:11 +01:00
viewlib_frame.h ++eeschema 2012-01-09 11:24:01 -06:00
viewlibs.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00