5 ms·
I think I can summarize your point of view as, "any use of floats should be treated as undefined behavior, so you get what you deserve." And that says nothing
by xscott 2y ago
I think I can summarize your point of view as, "any use of floats should be treated as undefined behavior, so you get what you deserve."
And that says nothing about whether implicit conversions are a good idea or not.
- Dylan16807 2y agoThe specific type of conversion is one I don't see as a big issue. The programmer deliberately decided to use an imprecise data type for the calculation. But more importantly, I'm saying that the problematic rounding can occur even if your tower does not have both bigint and float. It can happen even if every layer can completely represent every value of the layer above it. Do you have any complaints that are unique to a tower that has both bigint and float, and don't apply to towers that only have float? To elaborate on that, an implicit cast directly from a single bigint to a single float won't happen with the rules in the wikipedia article. You'd have to do something like bigint+float, which can have horrible rounding errors, but those horrible rounding errors are also present in float+float. And you can even have these problems without a tower. So I don't see how the bigint and float scenario is an argument against towers.
- xscott 2y agoFrom a distance, I kind of like Scheme, so I went and re-read the R5RS section on the topic. To me, the numeric tower (generalized) says: N < Z < Q < R < C < H ℕ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ ⊂ ℍ That's a nice statement about idealized sets of numeric values. So `integer?` implies `rational?` implies `real?` implies `complex?` implies `number?` in Scheme predicates and type conversions. But no programming language can have "Reals" (they aren't computable), so floats are a common/useful approximation. And in actuality `bigint?` doesn't imply `floating?`, and `floating?` doesn't imply `bigint?`. Neither is a strict subset of the other, and because of this you can easily find examples where implicit conversion does something "questionable". You've made it about rounding errors, but I'm trying to criticize something about pretending they are subtypes/subsets. Claiming it's a tower and hand waving about exact/inexact doesn't make it a tower, and so I think implicit conversion for these is a poor choice. You can have little subset relations for implicit conversions: float32? implies float64? float64? implies complex64? float32? implies complex32? complex32? implies complex64? fixint? implies bigint? fixint? implies rational? bigint? implies rational? Since this is supposedly in a discussion about JavaScript, maybe even: fixint? implies float64? All of those relate true subsets for the collection of values they can represent, but it's not much of a tower. It's more a collection of DAGs.
- Dylan16807 2y ago> But it's not much of a tower, and it's more of a collection DAGs. > I'm trying to criticize something about pretending they are subtypes/subsets. Claiming it's a tower and hand waving about exact/inexact doesn't make it a tower I thought we established right away that it's not a single tower. The description in the wikipedia page is two towers with links between them. (Or at least it's two if you don't waste effort on things like having both float64 and complex32.) But I don't see any hand waving. The relationships and conversions are very clear. That's why I interpreted your complaint as being more about the specific operation. So with your correction, I need you to explain where you see hand-waving. If you just don't like the name "Tower" for an implementation that has both bignums and floats then okay I agree I guess?
- xscott 2y ago> I thought we established right away that it's not a single tower. Where did we say that? The first picture on the Wikipedia page shows the tower as a linear stack of items from set theory. The Scheme predicates are named similarly. This is the appealing myth. > The description in the wikipedia page is two towers with links between them. Not on the page I'm seeing. Are you reading the English page? At the bottom, I see a tree of abstract types (sets). This shows that you can traverse (Integer to Rational to Real) and (Float to Real) to find the common abstract type Real. But there isn't actually a Real type you can do operations with. You've got concrete BigInt and Float64, and even if Real is implemented as a C-style tagged-union of the two types, you still need to pick one or the other for doing operations like addition. Then the Scheme standard says stuff like, "try to be exact when you can, but inexact is ok sometimes". So all the set theory justification is out the window, and it's really just an ad hoc rule. It's just not as elegant as it seems, and it gives an unsound justification to making implicit conversions. > If you just don't like the name "Tower" then okay I agree I guess? Please don't do that. I've tried to clarify details in response to your questions, but if you're just going to dismiss it with some snarky crap like that then you can go fuck yourself. Reply if you want, but I'm guessing we're done here.
- Dylan16807 2y ago