Revision 7fa2f28e
Added by David Sorber over 4 years ago
| software/fixed/fixed_test.cc | ||
|---|---|---|
|
#include <cmath>
|
||
|
#include <cstdint>
|
||
|
#include <limits>
|
||
|
#include <iomanip>
|
||
|
#include <iostream>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
#include "fixed.h"
|
||
|
#include "int128.h"
|
||
|
|
||
|
// g++ fixed_test.cc -o fixed_test
|
||
|
int main(int argc, char** argv)
|
||
| ... | ... | |
|
//~ 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;
|
||
|
|
||
|
|
||
|
uint128_t big = 1098298217598174ULL;
|
||
|
std::cout << "BIG INT: " << big << std::endl;
|
||
|
big *= 1098982694765;
|
||
|
std::cout << "BIGGER INT: " << big << std::endl;
|
||
|
|
||
|
std::cout << "INT128T MAX: " << std::numeric_limits<int128_t>::max() << std::endl;
|
||
|
std::cout << "UINT128T MAX: " << std::numeric_limits<uint128_t>::max() << std::endl;
|
||
|
|
||
|
strVal = "-1207010734831637608463359110";
|
||
|
int128_t s128Val = strtoll_128(strVal, nullptr, 0);
|
||
|
std::cout << "String value: " << strVal << std::endl;
|
||
|
std::cout << "Parsed value: " << s128Val << std::endl;
|
||
|
|
||
|
strVal = "991207010734831637608463359110888";
|
||
|
uint128_t u128Val = strtoull_128(strVal, nullptr, 0);
|
||
|
std::cout << "String value: " << strVal << std::endl;
|
||
|
std::cout << "Parsed value: " << u128Val << std::endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
Adding int128.h header with support for GCC specific int128_t and
uint128_t types.