On Fri, Aug 7, 2020 at 5:18 PM Rami Ojares <[email protected]> wrote:
> Hi Mike, > > When dealing with a fractional representation of a number having numerator > and denominator, > the system would have to find the greatest common factor (of numerator and > denominator) to represent a number uniquely (when comparing). > For addition you would have to make the denominators equal. > Yeah, I understand those tradeoffs ... but I think mostly we are not cpu limited in any case. Strictly speaking you wouldn't need to find the gcf. You could just cross multiply the two and compare them that way ... probably a lot of scope for optimisation. So having this kind of type would require a bit more computing than a > decimal number where the denominator is fixed to be 10. > > The only upside would be the ability to represent 1/3 (and similar numbers > that can only be represented as repeating decimals) exactly but if you now > have 64 bit integer to represent a decimal then you would need a lot of > precision before noticing any practical difference. Furthermore you could > have even more precision using larger integers than long (eg. java's > BigInteger). > Of course in mathematics you might have uses for fractional representation. > In which problem area do you have a need for absolute precision? > I have rationals in the application level type system. They are for doing calculations without creating rounding anomalys, and they work well. Some are stored (some are calculated) and current state is a hack because they are stored as decimals. In practice it works ok, but I wanted to replay changes (transactions) and I get something different because of this hack essentially. The thing is a replay system slightly different is almost as bad as completely broken because it is hard to verify anything, fix other issues... etc. > And finally we would still be unable to represent the irrational numbers > exactly. > What kind of representation would work for all real numbers? > Just curious. > Well indeed, otherwise we'd certainly all be using rationals. Fortunately I'm not doing much sin/squareroot when dealing with currencies and quantities ... The biggest challenge is perhaps handling the rounding, in anycase, in practice it's not really an issue if the value is merely the result of dividing a couple of user inputed (rational) fields. > - Rami > On 7.8.2020 18.38, Mike Goodwin wrote: > > >> What do you see as the driver for having the field be a column type? Have >> you looked into H2 function support? >> > > Hi Matt, > > Mostly just selfish reasons, but I do think there is a sound > engineering/computer science basis for having another numeric type. Decimal > types are arbitrary for computation, and we allow unlimited precision for > decimal numbers (I guess in practice they round before too long). It is to > avoid unnecessary rounding and wrinkles. > > I do think we tend to paper over these kind of issues in our industry and > as a consequence end up with mediocre standards such as SQL. The strength > of 'SQL' databases is the relational model not SQL. In anycase virtually > all databases don't conform and have their own superset of functionality. > > - mike > > -- > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/h2-database/CAOZwqwnhFnB8-Zny1CcK4G%2By3wduZWkMR%3DOC3ybvLSrag8kS5g%40mail.gmail.com > <https://groups.google.com/d/msgid/h2-database/CAOZwqwnhFnB8-Zny1CcK4G%2By3wduZWkMR%3DOC3ybvLSrag8kS5g%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > -- > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/h2-database/84bf5a41-0759-9654-6e7c-58be60eb0bc9%40gmail.com > <https://groups.google.com/d/msgid/h2-database/84bf5a41-0759-9654-6e7c-58be60eb0bc9%40gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/CAOZwqwkNfNV_F5B9R3t%3DWaJTiFj4s59R8%3D7BEYL551f_c582Sg%40mail.gmail.com.
