Conversation
|
It's a bad idea all around: NaN is a particularly terrible value as it defies basic logic (NaN != NaN, no other Null/None/nil type in history of mankind does that bullshit). In general Ormin needs to get more precise at NULL Handling, the users should be able to opt-into Option[T] for these Nullable entries. This will avoid the special case for |
What?! In SQL null != null. From Postgres manual:
Really, NaN != NaN is just basic logic. E.g. implying that if In terms of a null in CS and as a sentinel empty value, then sure it's bullshit. That's not how SQL or (most) Floats treat it for better or worse.
Sure, however SQLite is weird and doesn't handle float NaN's it seems. If you write a float NaN using Ormin to SQLite you currently then get That's why this is an opt in compile flag. SQLite can't store NaN it seems so the user should be able to decide the policy. Otherwise I have to write different code for Postgres and SQLite even with better |
|
An even more general solution could be allowing users to provide custom to/from hooks for SQL similar to json utils. Not sure how to do that with Ormin. Maybe there's a clean syntax for that. |
What? No. Do you also want |
I mean sure its nice if And there's corner cases where NaN != NaN can be useful when doing maths or SQL stuff.
Well agreed. Still doesn't help me serialize NaN from floats in either Postgres and SQLite. If a temperature sensor didn't record anything it should be NaN, not 0.0. That's huge PITA to filter from data when calculating averages, anomalies, etc. |
Nö, NaN is so broken that it should report Option[float] instead where there is a sane None value. It's like float's NaN and SQL's NULL was invented by people who knew nothing about type theory... Or programming for that matter. |
Haha, nah mate. The people who invented IEEE 754 NaN and SQL's NULL knew type theory quite well I'd wager. You just don't have to normally deal with the problems Looks like William Kahan was the lead for IEEE 754 standard and deep in the innards of numerical analysis while either of us were in diapers. :P Seems he knows his type/set/number theories well enough:
It wasn't an accident they chose what they did. NaN behavior isn't broken, it's just a best of the worst ways to represent some mathematical / numerical properties in floats that are hard to express. Floats are inherently mathematically incorrect, but they're practical. if-its-not-a-number-what-is-it-demystifying-nan-for-the-working-programmer expresses it well:
Especially this bit:
|
|
Claiming that the The citations argue for +/-Inf and NaN, they don't argue for "comparisons with NaN should always be special snowflakes". Here is how broken it really is: You cannot even |
Why is deciding that Choosing I think it’s more that programming languages suck and don’t provide a complete set of infix predicates for all the logic cases for floats. IEEE 754 also defined predicates for ==, =>, etc that do raise faults right? Why doesn’t Nim use those and throw a defect like it does for overflows. That’s much less broken logically.
Yes they do. That last paragraph I quoted talks about NaN equals and makes one case for it. It also mentions that signed Infs also have weird behavior for other predicates. In SQL there’s queries where Null <> Null being false is helpful as well and would be difficult or impossible to do otherwise.
And? There’s no inherent mathematical way to sort NaNs. That’s asking “is not-a-number greater than 3?” — there’s literally no proper answer. But for practical purposes folks define some |
No description provided.