Post ASA8dZ8sD3D55DFs2q by gwachob@sfba.social
(DIR) More posts by gwachob@sfba.social
(DIR) Post #ASA8dZ8sD3D55DFs2q by gwachob@sfba.social
2023-01-17T21:59:11Z
0 likes, 0 repeats
My software "hot take" that I've had for many years (which makes it a well seasoned, rich tasting hot take broth):When dealing with money, using floats is a bug. All the time.I would say "come at me bro" but that's toxically gendered, aggressive, and would generate responses I'm looking for. But it's kind of energy I get when I see bugs related to floating point and money.#CrankyAdvice#NotCommonPractice#SoftwareEngineering #Bug #currency #Money
(DIR) Post #ASA8dZe4L4ACdxqmfY by JorgeStolfi@mas.to
2023-01-26T01:48:47Z
0 likes, 0 repeats
@gwachob Several languages that have only one native "numeric" type, like javascript and excel, use double-precision floats to represent it. >>
(DIR) Post #ASA8da9GT57KCiRhIG by JorgeStolfi@mas.to
2023-01-26T01:49:49Z
0 likes, 0 repeats
@gwachob Using doubles for money is safe PROVIDED (1) one understands floating point really well, (2) all money amounts are stored as cents, not dollars, (3) amounts never exceed 2^50 cents, which is about 2 trillion USD, and (4) operations that may create fractions of cents are explicitly rounded.Unfortunately most people who compute with money don't even know the difference between integers and floats...
(DIR) Post #ASA8dae6cPmrkMsKMi by lxo@gnusocial.net
2023-01-29T15:22:47Z
0 likes, 1 repeats
but then, once someone realizes all of these points, they'd think (5) double is being used as an inefficient and narrow integer type; (6) int64_t would be better in all regards; (7) forcing doubles to behave like ints would only make sense if you don't have ints as a choice in the chosen language; and (8) languages that don't give you ints are probably not suited for the task at hand