Skip to content

B: Number

Havik2 edited this page Feb 24, 2018 · 5 revisions

Number

Overview

The Number class identifies values as numbers, includes arithmetic operations for numbers, has comparison operators, and identifies what type of number is being used.

Structure

Holds value of T for any number. Uses the enum class NumberType to hold the value of INTEGER, REAL, or RATIONAL. type_tag is used to label T.

Behavior

Has the arithmetic operations used for integer, rational, and real numbers +, -, *, /, %, |. The |, or operator, is used to produce an integer value from the /, divide operator if T is of type INTEGER. Also has the comparison operations ==, >, <, >=, <=, !=. The code also does not allow the user to set the value of T.

Example

#include <iostream>
#include "shaka_scheme/system/base/Integer.hpp"
#include "shaka_scheme/system/base/Real.hpp"
#include "shaka_scheme/system/base/Rational.hpp"
int main() {
std::cout<<"Number"<<std::endl;
shaka::Number n(45);
std::cout<<n.get()<<std::endl;
std::cout<<n.get_type()<<std::endl;
}
Clone this wiki locally