Revision 11ae9ac5
Added by David Sorber over 4 years ago
| software/fixed/fixed_test.cc | ||
|---|---|---|
|
#include <cstdint>
|
||
|
#include <iomanip>
|
||
|
#include <iostream>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
#include "fixed.h"
|
||
|
|
||
|
// g++ fixed_text.cc -o fixed_test
|
||
|
// g++ fixed_test.cc -o fixed_test
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
std::cout << "Fixed Type Test Util\n" << std::endl;
|
||
| ... | ... | |
|
|
||
|
std::cout << "Max fractional value: " << fixed_64_64::MAX_FRACTIONAL_VALUE << std::endl;
|
||
|
|
||
|
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;
|
||
|
|
||
|
//~ 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;
|
||
Additional improvements to the fixed point type. Also adding parse_test
which can be used to compare parse performance and a CMakeLists.txt.