Piethon  1.0
A Python-like interpreter using flex and bison.
Functions
number.cpp File Reference
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "exception.h"
#include "number.h"
Include dependency graph for number.cpp:

Go to the source code of this file.

Functions

ostream & operator<< (ostream &out, const Number &num)
 
bool operator== (const Number &lhs, const Number &rhs)
 
bool operator!= (const Number &lhs, const Number &rhs)
 
bool operator< (const Number &lhs, const Number &rhs)
 
bool operator> (const Number &lhs, const Number &rhs)
 
bool operator<= (const Number &lhs, const Number &rhs)
 
bool operator>= (const Number &lhs, const Number &rhs)
 

Function Documentation

◆ operator!=()

bool operator!= ( const Number lhs,
const Number rhs 
)

Definition at line 34 of file number.cpp.

34  {
35  return !(lhs == rhs);
36 }

◆ operator<()

bool operator< ( const Number lhs,
const Number rhs 
)

Definition at line 38 of file number.cpp.

38  {
39  if (lhs.type == INT && rhs.type == INT) {
40  return lhs.value.i < rhs.value.i;
41  } else if (lhs.type == FLOAT && rhs.type == FLOAT) {
42  return lhs.value.f < rhs.value.f;
43  } else if (lhs.type == INT && rhs.type == FLOAT) {
44  return lhs.value.i < rhs.value.f;
45  } else if (lhs.type == FLOAT && rhs.type == INT) {
46  return lhs.value.f < rhs.value.i;
47  } else {
48  throw UnknownType();
49  }
50 }
Definition: number.h:10
double f
Definition: number.h:18
Definition: number.h:9
int i
Definition: number.h:17

◆ operator<<()

ostream& operator<< ( ostream &  out,
const Number num 
)

Definition at line 10 of file number.cpp.

10  {
11  if (num.type == INT) {
12  return out << num.value.i;
13  } else if (num.type == FLOAT) {
14  return out << fixed << num.value.f;
15  } else {
16  throw UnknownType();
17  }
18 }
Definition: number.h:10
double f
Definition: number.h:18
Definition: number.h:9
int i
Definition: number.h:17

◆ operator<=()

bool operator<= ( const Number lhs,
const Number rhs 
)

Definition at line 66 of file number.cpp.

66  {
67  return !(lhs > rhs);
68 }

◆ operator==()

bool operator== ( const Number lhs,
const Number rhs 
)

Definition at line 20 of file number.cpp.

20  {
21  if (lhs.type == INT && rhs.type == INT) {
22  return lhs.value.i == rhs.value.i;
23  } else if (lhs.type == FLOAT && rhs.type == FLOAT) {
24  return lhs.value.f == rhs.value.f;
25  } else if (lhs.type == INT && rhs.type == FLOAT) {
26  return lhs.value.i == rhs.value.f;
27  } else if (lhs.type == FLOAT && rhs.type == INT) {
28  return lhs.value.f == rhs.value.i;
29  } else {
30  throw UnknownType();
31  }
32 }
Definition: number.h:10
double f
Definition: number.h:18
Definition: number.h:9
int i
Definition: number.h:17

◆ operator>()

bool operator> ( const Number lhs,
const Number rhs 
)

Definition at line 52 of file number.cpp.

52  {
53  if (lhs.type == INT && rhs.type == INT) {
54  return lhs.value.i > rhs.value.i;
55  } else if (lhs.type == FLOAT && rhs.type == FLOAT) {
56  return lhs.value.f > rhs.value.f;
57  } else if (lhs.type == INT && rhs.type == FLOAT) {
58  return lhs.value.i > rhs.value.f;
59  } else if (lhs.type == FLOAT && rhs.type == INT) {
60  return lhs.value.f > rhs.value.i;
61  } else {
62  throw UnknownType();
63  }
64 }
Definition: number.h:10
double f
Definition: number.h:18
Definition: number.h:9
int i
Definition: number.h:17

◆ operator>=()

bool operator>= ( const Number lhs,
const Number rhs 
)

Definition at line 70 of file number.cpp.

70  {
71  return !(lhs < rhs);
72 }