QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Rounding Class Reference

basic rounding class More...

#include <rounding.hpp>

+ Inheritance diagram for Rounding:
+ Collaboration diagram for Rounding:

Public Types

enum  Type {
  None , Up , Down , Closest ,
  Floor , Ceiling
}
 rounding methods More...
 

Public Member Functions

 Rounding ()=default
 default constructor More...
 
 Rounding (Integer precision, Type type=Closest, Integer digit=5)
 
Decimal operator() (Decimal value) const
 perform rounding More...
 

Inspectors

Integer precision_
 
Type type_ = None
 
Integer digit_
 
Integer precision () const
 
Type type () const
 
Integer roundingDigit () const
 

Detailed Description

basic rounding class

Tests:
the correctness of the returned values is tested by checking them against known good results.

Definition at line 35 of file rounding.hpp.

Member Enumeration Documentation

◆ Type

enum Type

rounding methods

The rounding methods follow the OMG specification available at http://www.omg.org/cgi-bin/doc?formal/00-06-29.pdf.

Warning:
the names of the Floor and Ceiling methods might be misleading. Check the provided reference.
Enumerator
None 

do not round: return the number unmodified

Up 

the first decimal place past the precision will be rounded up. This differs from the OMG rule which rounds up only if the decimal to be rounded is greater than or equal to the rounding digit

Down 

all decimal places past the precision will be truncated

Closest 

the first decimal place past the precision will be rounded up if greater than or equal to the rounding digit; this corresponds to the OMG round-up rule. When the rounding digit is 5, the result will be the one closest to the original number, hence the name.

Floor 

positive numbers will be rounded up and negative numbers will be rounded down using the OMG round up and round down rules

Ceiling 

positive numbers will be rounded down and negative numbers will be rounded up using the OMG round up and round down rules

Definition at line 44 of file rounding.hpp.

Constructor & Destructor Documentation

◆ Rounding() [1/2]

Rounding ( )
default

default constructor

Instances built through this constructor don't perform any rounding.

◆ Rounding() [2/2]

Rounding ( Integer  precision,
Type  type = Closest,
Integer  digit = 5 
)
explicit

Definition at line 71 of file rounding.hpp.

Member Function Documentation

◆ operator()()

Decimal operator() ( Decimal  value) const

perform rounding

Definition at line 29 of file rounding.cpp.

◆ precision()

Integer precision ( ) const

Definition at line 79 of file rounding.hpp.

◆ type()

Type type ( ) const

Definition at line 80 of file rounding.hpp.

◆ roundingDigit()

Integer roundingDigit ( ) const

Definition at line 81 of file rounding.hpp.

Member Data Documentation

◆ precision_

Integer precision_
private

Definition at line 83 of file rounding.hpp.

◆ type_

Type type_ = None
private

Definition at line 84 of file rounding.hpp.

◆ digit_

Integer digit_
private

Definition at line 85 of file rounding.hpp.