Thread: floating point pressision

  1. #1
    Unregistered
    Guest

    floating point pressision

    hi, i know this may have been posted before but i'd appreciate if you could save me a bit of time...

    i'm looking for a simple and fast floating point library that can keep pressision to 4 or 5 decimal digits. commersial stuff is out of question, and it'd be nice if it's something with source code...

    sorry for lame question but i'm realy pressed with time.

    thanx a lot

    regards,

    jim

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    If you all you need to do is specify the precision a floating point number is displayed with, then you can do that in the printf function call:
    Code:
    float number = 21.12345;
    
    printf(" %.2f ", number );
    The .2 specifies the precision, it also rounds up as neccessary.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well, with the advent of the FPU, a floating-point library will just use FPU opcodes to get the job done. It would be just as quick to code your own floating point functions in assembly and call them. If not, there are already several math libraries included with C that will handle this task. 4 or 5 decimal digits is not very precise when it comes to talking about precision in floating point variables. FPU data widths are all 80 bits so that might give you an idea of just how exact the FPU can be.

    I highly recommend getting some references on the FPU opcodes and using them. To use them only requires a miniscule amount of knowledge about assembler and they are extremely fast, especially on AMD's.

    If you don't want to do that, simply click the option - use floating point instructions - in your compiler options and the compiler will generate the appropriate opcodes/instructions for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM