Float vs Double
Float is 32 Bit, Double is 64 bit. If you develop in 32 bit, float should be faster (also on a G5 if you do anything with an UI, as Cocoa, Carbon and so on are all 32 bit). The f at the end tells the compiler that it is a float constant. If you do
the finished program will load the number as a double and then convert it to a float, which is slower than
where the number will be loaded directly as float.
double is more precise, but I've never had any problems with using floats anywhere. The difference is not that large for games, I suppose.
About your last question: Depends. A PowerPC can usually do an addition and a multiplication in a single instruction. The G5 can, if the code is well optimized, do two of both in one instruction. If you use Altivec, this number will be increased even more. On the other hand, it all depends on how well the code is written and then every instruction has to go through a pipeline, so the actual speed will be less. In the end, just write your code and if it's too slow, use Shark to find out where and optimize it. It is nearly impossible to tell how fast what piece of code is in real-life circumstances.
Code:
float foo = 2.0Code:
float foo = 2.0fdouble is more precise, but I've never had any problems with using floats anywhere. The difference is not that large for games, I suppose.
About your last question: Depends. A PowerPC can usually do an addition and a multiplication in a single instruction. The G5 can, if the code is well optimized, do two of both in one instruction. If you use Altivec, this number will be increased even more. On the other hand, it all depends on how well the code is written and then every instruction has to go through a pipeline, so the actual speed will be less. In the end, just write your code and if it's too slow, use Shark to find out where and optimize it. It is nearly impossible to tell how fast what piece of code is in real-life circumstances.
| Messages In This Thread |
|
Float vs Double - bwalters - Dec 10, 2005, 10:04 AM
Float vs Double - Cochrane - Dec 10, 2005 10:38 AM
Float vs Double - bwalters - Dec 10, 2005, 10:52 AM
Float vs Double - zKing - Dec 10, 2005, 12:18 PM
Float vs Double - OneSadCookie - Dec 10, 2005, 03:56 PM
Float vs Double - zKing - Dec 10, 2005, 04:29 PM
Float vs Double - jfaller - Dec 12, 2005, 10:58 AM
Float vs Double - Zekaric - Dec 12, 2005, 11:18 AM
Float vs Double - zKing - Dec 12, 2005, 11:40 AM
Float vs Double - Oblivion - Dec 12, 2005, 03:58 PM
Float vs Double - Najdorf - Dec 19, 2005, 11:08 AM
Float vs Double - ThemsAllTook - Dec 19, 2005, 12:40 PM
Float vs Double - Najdorf - Dec 19, 2005, 03:05 PM
Float vs Double - Fenris - Dec 19, 2005, 04:15 PM
Float vs Double - jfaller - Dec 20, 2005, 07:07 AM
Float vs Double - Fenris - Dec 20, 2005, 09:21 AM
Float vs Double - Zekaric - Dec 20, 2005, 10:25 AM
Float vs Double - Fenris - Dec 20, 2005, 12:29 PM
Float vs Double - OneSadCookie - Dec 20, 2005, 12:39 PM
Float vs Double - skyhawk - Dec 20, 2005, 01:10 PM
Float vs Double - Zekaric - Dec 20, 2005, 01:45 PM
Float vs Double - Fenris - Dec 20, 2005, 05:40 PM
Float vs Double - Zekaric - Dec 20, 2005, 06:10 PM
Float vs Double - jfaller - Jan 3, 2006, 02:44 PM
Float vs Double - DoG - Jan 3, 2006, 03:49 PM
|
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| float value changes when passed to function | kendric | 5 | 3,147 |
Nov 15, 2009 01:57 PM Last Post: kendric |
|

