Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
StdDefs.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2014-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20/****************************************************************************/
21#include "StdDefs.h"
22#include <sstream>
23
24
25// set by option --precision (see SystemFrame.cpp)
26int gPrecision = 2;
30bool gHumanReadableTime = false;
31bool gSimulation = false;
35std::string gLanguage = "C";
37
38bool gDebugFlag1 = false;
39bool gDebugFlag2 = false;
40bool gDebugFlag3 = false;
41bool gDebugFlag4 = false;
42bool gDebugFlag5 = false;
43bool gDebugFlag6 = false;
44
45double truncate(double x, int fractionBits) {
46 return ceil(x * (1 << fractionBits)) / (1 << fractionBits);
47}
48
49double roundBits(double x, int fractionBits) {
50 const double x2 = x * (1 << fractionBits);
51 const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);
52 return rounded / (1 << fractionBits);
53}
54
55double roundDecimal(double x, int precision) {
56 const double p = pow(10, precision);
57 const double x2 = x * p;
58 return (x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5)) / p;
59}
60
61int
62getScalingQuota(double frac, int loaded) {
63 if (frac < 0 || frac == 1.) {
64 return 1;
65 }
66 const int base = (int)frac;
67 const int resolution = 1000;
68 const int intFrac = (int)floor((frac - base) * resolution + 0.5);
69 // apply % twice to avoid integer overflow
70 if (((loaded % resolution) * intFrac) % resolution < intFrac) {
71 return base + 1;
72 }
73 return base;
74}
75
76/****************************************************************************/
int gPrecisionEmissions
Definition StdDefs.cpp:27
int getScalingQuota(double frac, int loaded)
Returns the number of instances of the current object that shall be emitted given the number of loade...
Definition StdDefs.cpp:62
double truncate(double x, int fractionBits)
discrds mantissa bits beyond the given number
Definition StdDefs.cpp:45
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
bool gDebugFlag3
Definition StdDefs.cpp:40
double gWeightsRandomFactor
Definition StdDefs.cpp:33
double roundBits(double x, int fractionBits)
round to the given number of mantissa bits beyond the given number
Definition StdDefs.cpp:49
double gWeightsWalkOppositeFactor
Definition StdDefs.cpp:34
int gPrecisionRandom
Definition StdDefs.cpp:29
bool gDebugFlag5
Definition StdDefs.cpp:42
std::string gLanguage
the language for GUI elements and messages
Definition StdDefs.cpp:35
bool gSimulation
Definition StdDefs.cpp:31
bool gDebugFlag2
Definition StdDefs.cpp:39
bool gHumanReadableTime
Definition StdDefs.cpp:30
bool gIgnoreUnknownVClass
Definition StdDefs.cpp:32
bool gDebugFlag6
Definition StdDefs.cpp:43
double roundDecimal(double x, int precision)
round to the given number of decimal digits
Definition StdDefs.cpp:55
bool gDebugFlag4
Definition StdDefs.cpp:41
bool gDebugFlag1
global utility flags for debugging
Definition StdDefs.cpp:38
int gPrecisionGeo
Definition StdDefs.cpp:28
int GUIDesignHeight
the default size for GUI elements
Definition StdDefs.cpp:36