When using g++ on Windows, how may I disable floating point?

Pages: 12
I don't know what OP's trying to do, but binary floating point is unusable for calculations dealing with money.


Honestly, you shouldn't be using floating point in accounting, ever.

If you need subunits, then make that your denomination. Measure everything in pennies if you are in the US. If you have a floating point quantity that needs conversion by something that specifies a sub-penny quantity (a junk stock price or a gallon of gasoline, for example) then do that math FIRST to determine the valuation, then the valuation will be priced exactly as an integer in the currency of choice.

You never want to see:

1.01
1.01
1.05
------
3.08
on a receipt because there's "hidden" value in any of the terms. This is true regardless of the base number system you use.

No floats. Ints and formatted print statements.

Related:
Don't compute the sales tax on each item. Compute the sales tax on all taxable items at the end of the receipt. Same reason. If there's different types of sales tax, list the different sales taxes at the bottom and add them up. (For example, a city might impose a 1% sales tax on everything, while the state imposes a 5.5% sales tax but exempts food items. Compute the city and state tax at the last step, don't compute it for each item based on category as you stream thru the receipt... if you have to stream the receipt, keep a total of taxable, not taxed. multiply last.)
Last edited on
Last edited on
At risk of flogging a dead horse, I consider the best answer to the question

how may I disable floating point?

to be:

Don't have float or double anywhere in your source code (EDIT: addition prompted by Helios)... or any other source code or libraries you're using.

That's it. If you want your code to NOT use floating point, that's how you do it. If there was a switch that told your compiler not to use floating point values, what should it do when it finds you using a floating point value in your source? Should it just refuse to compile?

If you want to NOT use floating point, then your code should contain no float, no double, and no numbers that aren't integers.

You could put

1
2
#define float DONT_USE_FLOAT
#define double DONT_USE_DOUBLE 


in a header and then your code wouldn't compile if it contained float or double, but you would still have the risk of something like auto = 0.01 in your code.

If you want your code to not contain float, double, or numbers that aren't integers, don't type them.
Last edited on
If you do that compilation may fail even if you don't actually use floats. For example, if you include a library that uses floats in its interface.
On the other hand, a library that you're including may use floats internally and you would have no way of knowing, let alone failing compilation because of it.
Topic archived. No new replies allowed.
Pages: 12