When performing calculations with floating point variables, why are the results not the same as a ordinary calculater.
When performing calculations with floating point variables, why are the results not the same as a ordinary calculater.
floats, doubles and calculators all use different levels of precision.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
all the data types in c have different precision as told by salem.
And to be amazed by this thing,store any int like 3 in float when you print the float it will contain 2.9999....
Most calculators, AFAIK, use their own data type for handling floating point arithmetic. This is usually done quite easily in C++ using operator overloading and such to create a class that will handle larger, more accurate floating point operations at a small cost of speed. In C, the task is a bit more of a challenge to accomplish, but it is definitely possible.