fork download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. class Pi {
  6. public:
  7. Pi() {}
  8.  
  9. operator float() const {
  10. return std::atan(1.0f)*4.0f;
  11. }
  12.  
  13. operator double() const {
  14. return std::atan(1.0)*4.0;
  15. }
  16. };
  17.  
  18. const Pi pi;
  19.  
  20. template<typename T>
  21. T operator*(const Pi& pi, T&& other)
  22. {
  23. return static_cast<T>(pi) * std::forward<T>(other);
  24. }
  25.  
  26. int main() {
  27. std::cout << std::setprecision(50) << pi * 1.0f << std::endl;
  28. std::cout << std::setprecision(50) << pi * 1.0 << std::endl;
  29. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
3.1415927410125732421875
3.141592653589793115997963468544185161590576171875