Skip to content

Instantly share code, notes, and snippets.

@Sam-Belliveau
Last active January 6, 2019 21:51
Show Gist options
  • Select an option

  • Save Sam-Belliveau/cc097ed7c7cd1938631a7488a375c0cd to your computer and use it in GitHub Desktop.

Select an option

Save Sam-Belliveau/cc097ed7c7cd1938631a7488a375c0cd to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdint>
using Int = std::uintmax_t;
using Float = long double;
constexpr Float getPhi()
{
Float Phi = 1;
for(Int i = 0; i < 0xffff; ++i)
Phi = 1/Phi + 1;
return Phi;
}
constexpr Float Phi = getPhi();
Int getNextInt(Int num)
{ return (Float(num)*Phi) + Float(0.5); }
Int getLastInt(Int num)
{ return (Float(num)/Phi) + Float(0.5); }
int main(int argc, char** argv)
{
while(1)
{
std::cout << "Enter Number: ";
std::string inputStr;
std::getline(std::cin, inputStr);
const Int input = std::stoll(inputStr);
std::cout
<< getLastInt(getLastInt(input)) << ' '
<< getLastInt(input) << " ["
<< input << "] "
<< getNextInt(input) << ' '
<< getNextInt(getNextInt(input)) << "\n\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment