Thread: basic arithmatic

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    51

    basic arithmatic

    When performing calculations with floating point variables, why are the results not the same as a ordinary calculater.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    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.

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    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....

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic Window Creation, Dev C++ 4.9.9.0 Linking Error
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2004, 06:03 PM