Skip to content

Instantly share code, notes, and snippets.

@sr229
Last active August 21, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sr229/1faded351a106fe25bf3a253a6616b0d to your computer and use it in GitHub Desktop.
Save sr229/1faded351a106fe25bf3a253a6616b0d to your computer and use it in GitHub Desktop.
CS-111: Floating Point Arithmetic
/*
* Copyright 2019 (c) Ralph Wilson Aguilar
* For CS-111
* Do not copy or redistribute without permission.
*/
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
float x, y;
const float pi = 3.14159265359;
cout << "Enter the value for x: ";
cin >> x;
/*
* There's nothing really special about this, we just translated the algebraic equation from here.
* So how this works is basically, we put x to the power of zero,
* put pi in the power of zero, then solve the first part of the equation
* which is x^2 / pi ^2 (x^2 + 1/2 or 0.5). Once we have a value of the first part,
* We then move on the the second one, with the same principles we used in the first one.
* This is very confusing by its own as the way we should put the parentheses to denote proper PEMDAS
* really threw everyone off. Basically what we did here is to wrap the divisor in another sub-expression
* so it solves properly.
*/
y = ( (pow(x, 2.0)) / ( (pow(pi , 2.0)) * ( (pow(x, 2.0)) + 0.5 ) ) ) * ( 1 + (pow(x, 2.0)) / ( (pow(pi, 2.0)) * pow(( ((pow(x, 2.0)) - 0.5 )), 2.0) ) );
cout << "y = " << y << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment