• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 18089177727

29 Sep 2025 07:23AM UTC coverage: 73.914% (+0.1%) from 73.816%
18089177727

Pull #2265

github

web-flow
Merge 13a7b3b53 into 787317697
Pull Request #2265: Fix potential dangling reference in MultiCubicSpline

2 of 2 new or added lines in 1 file covered. (100.0%)

219 existing lines in 29 files now uncovered.

57063 of 77202 relevant lines covered (73.91%)

8763673.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/ql/math/rounding.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2004 Decillion Pty(Ltd)
5

6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8

9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14

15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19

20
/*! \file rounding.hpp
21
    \brief Rounding implementation
22
*/
23

24
#include <ql/math/rounding.hpp>
25
#include <ql/errors.hpp>
26

27
namespace QuantLib {
28

29
    static inline Real fast_pow10(Integer precision) {
30
        // Providing support for truncating up to 16 decimal places after dot
31
        constexpr static double pow10_lut[0x20] = {
32
            1.0E0,  1.0E1,  1.0E2,  1.0E3,  1.0E4,  1.0E5,
33
            1.0E6,  1.0E7,  1.0E8,  1.0E9,  1.0E10, 1.0E11,
34
            1.0E12, 1.0E13, 1.0E14, 1.0E15, 1.0E16
35
            /*the rest of the numbers are zeros*/};
36
        // Skipping precision input value checks without causing a crash
37
        return pow10_lut[precision & 0x1F];
642,041✔
38
    }
39

40
    Decimal Rounding::operator()(Decimal value) const {
642,045✔
41

42
        if (type_ == None)
642,045✔
43
            return value;
44

45
        Real mult = fast_pow10(precision_);
642,041✔
46
        bool neg = (value < 0.0);
47
        Real lvalue = std::fabs(value)*mult;
642,041✔
48
        Real integral = 0.0;
642,041✔
49
        Real modVal = std::modf(lvalue,&integral);
642,041✔
50
        lvalue -= modVal;
642,041✔
51
        switch (type_) {
642,041✔
52
          case Down:
53
            break;
54
          case Up:
21✔
55
            if (modVal != 0.0)
21✔
56
                lvalue += 1.0;
20✔
57
            break;
58
          case Closest:
641,950✔
59
            if (modVal >= (digit_/10.0))
641,950✔
60
                lvalue += 1.0;
233,672✔
61
            break;
62
          case Floor:
21✔
63
            if (!neg) {
21✔
64
                if (modVal >= (digit_/10.0))
15✔
65
                    lvalue += 1.0;
6✔
66
            }
67
            break;
68
          case Ceiling:
21✔
69
            if (neg) {
21✔
70
                if (modVal >= (digit_/10.0))
6✔
71
                    lvalue += 1.0;
2✔
72
            }
73
            break;
UNCOV
74
          default:
×
UNCOV
75
            QL_FAIL("unknown rounding method");
×
76
        }
77
        return (neg) ? Real(-(lvalue / mult)) : Real(lvalue / mult);
642,041✔
78
    }
79

80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc