Project

General

Profile

Download (2.74 KB) Statistics
| Branch: | Tag: | Revision:
835f4592 David Sorber
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
11ae9ac5 David Sorber
#include <stdexcept>
835f4592 David Sorber
#include "fixed.h"

11ae9ac5 David Sorber
// g++ fixed_test.cc -o fixed_test
835f4592 David Sorber
int main(int argc, char** argv)
{
std::cout << "Fixed Type Test Util\n" << std::endl;

fixed_64_64 foobar;
std::cout << "Type size: " << sizeof(fixed_64_64) << std::endl;
std::cout << "Integer decimal digits: " << fixed_64_64::integer_decimal_digits << std::endl;
std::cout << "Fractional decimal digits: " << fixed_64_64::fractional_decimal_digits << std::endl;
std::cout << "Max integer value: " << fixed_64_64::MAX_INTEGER_VALUE << std::endl;
std::cout << "Max fractional value: " << fixed_64_64::MAX_FRACTIONAL_VALUE << std::endl;
11ae9ac5 David Sorber
std::cout << std::endl;
std::cout << "Value: " << foobar << std::endl;
fixed_64_64 quxbar(3, 1415926353);
std::cout << "Value: " << quxbar << std::endl;
fixed_64_64 intMax(999999999999999999ULL);
std::cout << "Value: " << intMax << std::endl;
try
{
fixed_64_64 intOverflow(1999999999999999999ULL);
std::cout << "Value: " << intMax << std::endl;
}
catch (const std::out_of_range& excep)
{
std::cout << "Integer overflow caught" << std::endl;
}
fixed_64_64 fracMax(0, 9999999999999999999ULL);
std::cout << "Value: " << fracMax << std::endl;
try
{
fixed_64_64 fracOverflow(0, 10000000000000000001ULL);
}
catch (const std::out_of_range& excep)
{
std::cout << "Fractional overflow caught" << std::endl;
}
fixed_64_64 value1;
fixed_64_64 value2;
const char* strVal = "100.1";
value1.parse(strVal);
std::cout << "String value: " << strVal << std::endl;
std::cout << "Parsed value: " << value1 << std::endl;
strVal = "100";
value2.parse(strVal);
std::cout << "String value: " << strVal << std::endl;
std::cout << "Parsed value: " << value2 << std::endl;
std::cout << value1 << " == " << value2 << " --> " << (value1 == value2) << std::endl;
std::cout << value1 << " != " << value2 << " --> " << (value1 != value2) << std::endl;
std::cout << value1 << " > " << value2 << " --> " << (value1 > value2) << std::endl;
std::cout << value1 << " < " << value2 << " --> " << (value1 < value2) << std::endl;
std::cout << value1 << " >= " << value2 << " --> " << (value1 >= value2) << std::endl;
std::cout << value1 << " <= " << value2 << " --> " << (value1 <= value2) << std::endl;
835f4592 David Sorber
//~ double foo = std::pow(10, 18);
//~ std::cout << "Foo: " << std::fixed << std::setprecision(0) << foo << std::endl;
//~ std::cout << "Foo: " << std::fixed << std::setprecision(0) << (static_cast<uint64_t>(foo) - 1) << std::endl;
return 0;
}