Skip to content

Instantly share code, notes, and snippets.

@usagi
Created August 22, 2011 11:45
Show Gist options
  • Save usagi/1162205 to your computer and use it in GitHub Desktop.
Save usagi/1162205 to your computer and use it in GitHub Desktop.
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <chrono>
main(){
namespace c = std::chrono;
typedef c::duration<double> real64_seconds;
typedef c::duration<float> real32_seconds;
auto pi = "3.1415926535897932384626433832795028841971";
auto a = real64_seconds(boost::lexical_cast<double>(pi));
auto b = c::duration_cast<real32_seconds>(a);
std::cout
<< pi << "\n"
<< boost::format("%.32f") % a.count() << "\n"
<< c::duration_cast<c::milliseconds>(a).count() << "\n"
<< c::duration_cast<c::microseconds>(a).count() << "\n"
<< c::duration_cast<c::nanoseconds>(a).count() << "\n"
<< c::duration_cast<real32_seconds>(a).count() << "\n"
<< boost::format("%.32f") % b.count() << "\n"
<< c::duration_cast<c::nanoseconds>(b).count() << "\n"
;
}
@usagi
Copy link
Author

usagi commented Aug 22, 2011

(result)

3.1415926535897932384626433832795028841971
3.14159265358979311599796346854419
3141
3141592
3141592653
3.14159
3.14159274101257324218750000000000
3141592832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment