I remember having a discussion with one of my math peers about floiting point error but it seems different than that. For example in c++
#Include <iostream></iostream>
#Include <cmath></cmath>
Using namespace std
Int main ()
{
\ declaration of string value
string X=" "
\ ui to get an input
cout << "Enter a numerical value";
cin >> X;
cout << "\n" << endl;
*conversion, redeclaration with associated values *\
const double pi =3.1415
double stragcel = stof(X) * pi * 2
\ print of your cute twinkry
cout << "The amount of cute twinkry in your soy titties is " << stragcel << " inches squared. You might wanna get that checked out." << " In terms of the range of the oscillations of your cute twinkry it is " << sin(stragcel) << " to " << sin(-stragcel) << ". This is dangerously off the charts. We cannot help your cute twinkry, sir." << endl;
return 0;
}I have done similar things with floating points but the error seems to be constant with int, float, and double. What is it?
Jump in the discussion.
No email address required.
It's just floating point error. Try
stod
instead ofstof
. The latter is giving you a single-precision float which only has a few decimal digits of precision.Jump in the discussion.
No email address required.
Must be why there was such and error with decimal values longer than 5 bits
Jump in the discussion.
No email address required.
More options
More options