LCOV - code coverage report
Current view: top level - src/utils/common - StdDefs.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 10 16 62.5 %
Date: 2024-05-02 15:31:40 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2014-2024 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             : /****************************************************************************/
      14             : /// @file    StdDefs.cpp
      15             : /// @author  Jakob Erdmann
      16             : /// @author  Michael Behrisch
      17             : /// @author  Laura Bieker
      18             : /// @date    2014-01-07
      19             : ///
      20             : /****************************************************************************/
      21             : #include "StdDefs.h"
      22             : #include <sstream>
      23             : 
      24             : 
      25             : // set by option --precision (see SystemFrame.cpp)
      26             : int gPrecision = 2;
      27             : int gPrecisionGeo = 6;
      28             : int gPrecisionRandom = 4;
      29             : bool gHumanReadableTime = false;
      30             : bool gSimulation = false;
      31             : double gWeightsRandomFactor = 1;
      32             : double gWeightsWalkOppositeFactor = 1;
      33             : std::string gLanguage = "C";
      34             : 
      35             : bool gDebugFlag1 = false;
      36             : bool gDebugFlag2 = false;
      37             : bool gDebugFlag3 = false;
      38             : bool gDebugFlag4 = false;
      39             : bool gDebugFlag5 = false;
      40             : bool gDebugFlag6 = false;
      41             : 
      42           0 : double truncate(double x, int fractionBits) {
      43           0 :     return ceil(x * (1 << fractionBits)) / (1 << fractionBits);
      44             : }
      45             : 
      46           0 : double roundBits(double x, int fractionBits) {
      47           0 :     const double x2 = x * (1 << fractionBits);
      48           0 :     const double rounded = x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5);
      49           0 :     return rounded / (1 << fractionBits);
      50             : }
      51             : 
      52     5517934 : double roundDecimal(double x, int precision) {
      53     5517934 :     const double p = pow(10, precision);
      54     5517934 :     const double x2 = x * p;
      55     5517934 :     return (x2 < 0 ? ceil(x2 - 0.5) : floor(x2 + 0.5)) / p;
      56             : }
      57             : 
      58             : int
      59     1351272 : getScalingQuota(double frac, int loaded) {
      60     1351272 :     if (frac < 0 || frac == 1.) {
      61             :         return 1;
      62             :     }
      63       90014 :     const int base = (int)frac;
      64             :     const int resolution = 1000;
      65       90014 :     const int intFrac = (int)floor((frac - base) * resolution + 0.5);
      66             :     // apply % twice to avoid integer overflow
      67       90014 :     if (((loaded % resolution) * intFrac) % resolution < intFrac) {
      68       56323 :         return base + 1;
      69             :     }
      70             :     return base;
      71             : }
      72             : 
      73             : /****************************************************************************/

Generated by: LCOV version 1.14