/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2014-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file StdDefs.cpp14/// @author Jakob Erdmann15/// @author Michael Behrisch16/// @author Laura Bieker17/// @date 2014-01-0718///19/****************************************************************************/20#include "StdDefs.h"21#include <sstream>222324// set by option --precision (see SystemFrame.cpp)25int gPrecision = 2;26int gPrecisionEmissions = 2;27int gPrecisionGeo = 6;28int gPrecisionRandom = 4;29bool gHumanReadableTime = false;30bool gSimulation = false;31bool gIgnoreUnknownVClass = false;32double gWeightsRandomFactor = 1;33double gWeightsWalkOppositeFactor = 1;34std::string gLanguage = "C";3536int GUIDesignHeight = 23;37int GUIDesignDialogButtonsHeight = 32;3839bool gDebugFlag1 = false;40bool gDebugFlag2 = false;41bool gDebugFlag3 = false;42bool gDebugFlag4 = false;43bool gDebugFlag5 = false;44bool gDebugFlag6 = false;4546double truncate(double x, int fractionBits) {47return ceil(x * (1 << fractionBits)) / (1 << fractionBits);48}4950double roundBits(double x, int fractionBits) {51const double x2 = x * (1 << fractionBits);52const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);53return rounded / (1 << fractionBits);54}5556double roundDecimal(double x, int precision) {57const double p = pow(10, precision);58const double x2 = x * p;59return (x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5)) / p;60}6162double roundDecimalToEven(double x, int precision) {63const int p = (int)pow(10, precision);64return std::nearbyint(x * p) / p;65}6667int68getScalingQuota(double frac, int loaded) {69if (frac < 0 || frac == 1.) {70return 1;71}72const int base = (int)frac;73const int resolution = 1000;74const int intFrac = (int)floor((frac - base) * resolution + 0.5);75// apply % twice to avoid integer overflow76if (((loaded % resolution) * intFrac) % resolution < intFrac) {77return base + 1;78}79return base;80}8182/****************************************************************************/838485