SUMO - Simulation of Urban MObility
StdDefs.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include "StdDefs.h"
26 
27 
28 // set by option --precision (see SystemFrame.cpp)
29 int gPrecision = 2;
30 int gPrecisionGeo = 6;
31 
32 bool gDebugFlag1 = false;
33 bool gDebugFlag2 = false;
34 bool gDebugFlag3 = false;
35 bool gDebugFlag4 = false;
36 
37 double truncate(double x, int fractionBits) {
38  return ceil(x * (1 << fractionBits)) / (1 << fractionBits);
39 }
40 
41 double roundBits(double x, int fractionBits) {
42  const double x2 = x * (1 << fractionBits);
43  const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);
44  return rounded / (1 << fractionBits);
45 }
46 
47 /****************************************************************************/
48 
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:32
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:29
bool gDebugFlag3
Definition: StdDefs.cpp:34
int gPrecisionGeo
Definition: StdDefs.cpp:30
bool gDebugFlag4
Definition: StdDefs.cpp:35
double roundBits(double x, int fractionBits)
round to the given number of mantissa bits beyond the given number
Definition: StdDefs.cpp:41
double truncate(double x, int fractionBits)
discrds mantissa bits beyond the given number
Definition: StdDefs.cpp:37
bool gDebugFlag2
Definition: StdDefs.cpp:33