home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18904 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  1.8 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!usc!srhqla!quest!kdq
  2. From: kdq@quest.UUCP (Kevin D. Quitt)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: speed?  double vs. float.  math.h??
  5. Message-ID: <PRmewB2w165w@quest.UUCP>
  6. Date: Sat, 26 Dec 92 11:31:48 PST
  7. References: <1hh801INNab1@agate.berkeley.edu>
  8. Reply-To: srhqla!quest!kdq
  9. Organization: Job quest  (805) 251-8210,  So Cal: (800) 400-8210
  10. Lines: 30
  11.  
  12. c60b-3hu@web-3c.berkeley.edu (Paul Hsu) writes:
  13.  
  14. >      I'm currently writing a C program where it needs to do lots and lots of
  15. > trig calculations.  But I would like the program to run really really fast.
  16. > So I'm concerned about the speed at which the calculations are carried out.
  17. > Trying to make the program run fast, I would like to have only float 
  18. > variables, instead of doubles, in my program.  But in the standard math 
  19. > library, all the functions take in arguments and return values in the type 
  20. > double.  So, what should I do?  First of all, should I even be concerned 
  21. > about the speed difference between doing calculations in float and doing the
  22. > calculations in doubles?  If yes, how should I go about in making the math 
  23. > functions to accept and return floats?  Casting them won't help....  it'll 
  24. > only take more time in the type conversion.  Any suggestion?
  25.  
  26.     It depends on your machine.  If your machine uses IEEE format
  27. floating point, and has hardware to do the calculations, then the
  28. internal calculation format is probably always double, if not long
  29. double.  (Motorola's FPUs use the 96bit long double format.  Intel's
  30. FPUs use double format).  You might want to benchmark your program
  31. per:
  32.  
  33. typdef float    FP;
  34.  and define all your floats as type FP.  Next time, use:
  35.  
  36. typedef double    FP;
  37.  
  38.  
  39.  _
  40. Kevin D. Quitt      96.37% of all statistics are made up.     srhqla!quest!kdq
  41.