Re:C-style: My favorite C programming practices
by teddyh on Monday May 20, 2024 @06:51AM
(#40414132)
I think you used the word “panacea” incorrectly. Judging by context, I would guess that the word “band-aid” would better convey your intended meaning.
Re:C-style: My favorite C programming practices
by nine_k on Monday May 20, 2024 @07:43AM
(#40414420)
A "panacea" is something that cures.every illness. 64-bit floats could do just that, in the cases listed. The cost of it may be higher than one cares to pay though.
And when the cure fails to be adequate, well, it becomes a band-aid, a temporary measure in search of a real solution.
Re:C-style: My favorite C programming practices
by zbentley on Monday May 20, 2024 @08:40AM
(#40414822)
Perhaps "placebo" was intended?
Re:C-style: My favorite C programming practices
by a1369209993 on Monday May 20, 2024 @02:08PM
(#40418261)
IIUC, they're using the word itself correctly, but they mean "double precision is often used with the intent of it being a panacea".
Re:C-style: My favorite C programming practices
by orthoxerox on Monday May 20, 2024 @08:02AM
(#40414519)
Are there C++ libs that use floating points for timestamps? I was under the impression that most stacks have accepted int64 epoch microseconds as the most reasonable format.
Re:C-style: My favorite C programming practices
by gpderetta on Monday May 20, 2024 @08:37AM
(#40414803)
> int64 epoch microseconds
surely nanoseconds is the truth.
Re:C-style: My favorite C programming practices
by orthoxerox on Monday May 20, 2024 @09:17AM
(#40415131)
LONG_MAX nanoseconds is just Friday, April 11, 2262 11:47:16.854 PM, not exactly a future-proof approach. I guess having Tuesday, September 21, 1677 12:12:43.145 AM as the earliest expressible timestamp neatly sidesteps the problem of proleptic Gregorian vs Julian calendars.
Re:C-style: My favorite C programming practices
by Const-me on Monday May 20, 2024 @09:30AM
(#40415262)
I think Apple is still doing that: https://developer.apple.com/documentation/foundation/nstimei...
Couple decades ago Microsoft did that too, VT_DATE in old OLE Automation keeping FP64 value inside. Luckily, their newer APIs and frameworks are using uint64 with 100-nanoseconds ticks.
Re:C-style: My favorite C programming practices
by ack_complete on Monday May 20, 2024 @12:13PM
(#40417040)
Don't have a publicly visible reference to give at the moment, but it's still sometimes seen where relative timestamps are being tracked, such as in an audio library tracking time elapsed since start. It's probably less used for absolute time where the precision problems are more obvious.
It's very common in games.
Integers are always an option, of course, but in this context it's hard to beat the convenience of just storing seconds in a floating point number.
Related: https://randomascii.wordpress.com/2012/02/13/dont-store-that...
OTOH, double precision is often just a panacea. If you don't know the precision requirements of your algorithm, how do you know that double precision will work either? Some types of errors will compound without anti-drifting protection in ways that are exponential, where the extra mantissa bits from a double will only get you a constant factor of additional time.
There are also current platforms where double will land you in very significant performance problems, not just a minor hit. GPUs are a particularly fun one -- there are currently popular GPUs where double precision math runs at 1/32 the rate of single precision.