Haskell is full of interesting number representations; all the machine integer types from Word8 & Int8 to Word64 & Int64. The Integer type is like Python’s int, an arbitrary precision integer limited by the size of your RAM. Ratio takes two integral types and gives you a ration, with the type alias Rational = Ratio Integer - this gives as much accuracy as you like, as long as your computation is computable with rational numbers, so many trig functions but not irrational values like pi. Then there’s the Numeric modules which define CReal, a type that lets you represent many more arbitrary computations, and when it’s evaluated you specify the precision, so asking for sin(180°) will give you pi to as much precision as you want (if you wait long enough). The Scientific type is somewhat similar to a base 10 float, which is represented as an Integer base and an Int exponent - it’s used in the most popular JSON package to precisely represent any valid JSON, not just what an be stored in an ieee-754 double.
@alian71414 күн бұрын
another haskeller in the wild, pog
@Dexter101x16 күн бұрын
Shows you how much of a newbie I'm still am, I didn't know that we could type "py" in the terminal and do all the maths things, let alone a short version of running code. Thanks
@Carberra16 күн бұрын
Best calculator in the world!
@valtersanches312416 күн бұрын
It's the REPL
@eboyd5316 күн бұрын
I learned from real world business programming decades ago to store amounts as integers and then divide by 10^precision to represent the amount. Mathematics with floating is not recommended if you need precision of the work. Accounting for instance needs to be precise and floating mathematics would always lose a penny or two depending on the number of operations.
@OtherTheDave14 күн бұрын
Unfortunately, most people just use Excel for financial stuff and assume it’s right.
@MoiMagnus1er14 күн бұрын
@@OtherTheDaveI'm still frustrated that Excel doesn't use shifted floating points by a factor 100. That would mean using integer arithmetics for number with only 2 digits after the point, and only having precision issues from floats at the third digit (which is rarely used).
@ChasRMartin10 күн бұрын
Good old cobol
@eboyd5310 күн бұрын
@@ChasRMartin I actually learned this using DEC BASIC. COBOL storage would have limited the amount of floating point math being done.
@BboyKeny9 күн бұрын
I built a project management + billing system and this is how I did it. For example VAT of 21%, I do "price in cents times 121" and then divide by 10000 just before presenting the price.
@boccobadz15 күн бұрын
Decimal type is almost everywhere because it's necessary for financial data.
@MLGJuggernautgaming14 күн бұрын
The syntax you use for f strings, how does that work? f”{ x=}”
@ryoschinlot915314 күн бұрын
I assume it is a pre-defined python thing, however the addition of this syntax contributes to feature creep, imo. Especially because the alternative is no more than `print(f"x = {x}")`
@MLGJuggernautgaming13 күн бұрын
@@ryoschinlot9153 Yeah yet another case where is more confusing than before.
@anon_y_mousse14 күн бұрын
I know it's not the intent for them to be useful for all math operations, but it'd still be nice if you could use the trigonometric functions. It looks like it stores them in a similar manner to `bc`, which I find strange. Also, I applaud your use of a shorthand when importing. I see so many people not bother to rename imports and use long and unwieldy names and it's frankly weird to me. Of course, it would be even easier if Python would add UDL's like C++ did. If you use C++ at all, I recommend you look up UDL's and make use of them, they are awesome.
@scarletevans447414 күн бұрын
2:10 is such rule of rounding really used while dealing with money too? Logic would say that rounding half a cent like that will lead to MILLIONS of difference over the course of billion transactions, where exactly do they use such rounding? And who takes that extra money that comes from it? 😀 (probably the bank does, but who wouldn't want a "free money" from rounding cents!)
@machadinhos17 күн бұрын
At the start of the video why is the camera so low? hahaha What a great video!
@Carberra16 күн бұрын
I forgot to raise the tripod lmao -- thankfully I realised for the rest I did in the batch!
@kirillsukhomlin303616 күн бұрын
It has been in many languages for at least 30 years.
@dipeshsamrawat795717 күн бұрын
Thank you 😊
@cmd_midac052215 күн бұрын
I prefer using mpmath (with gmpy2) for precise python calculations.
@ryankulczycki421516 күн бұрын
what about one divided by three, store the answer, multiply the answer by three, intuitively this would be one - but does decimal give that answer?
@Carberra16 күн бұрын
No -- it gives 0.999... to as much precision as you like. I can see _why_ it's done that, and realistically however you would go about rounding or quantizing that it would be correct, but yeah that is a strange one. I guess it's just a byproduct of trying to be as exact as possible, and in doing so making no approximations whatsoever.
@interwebslinger16 күн бұрын
It doesn't _necessarily_ give you 1, but you can get it to do so for most practical situations by quantizing it to a reasonable length, e.g. 10 decimals or whatever you need. In this sense I still find it more intuitive to work with than floats for most cases.
@costa_marco16 күн бұрын
@@interwebslinger You can use the 'fractions' module if you need exact rationals. If you need exact numbers, then you need to go full algebra like 'SymPy'.
@interwebslinger16 күн бұрын
@@costa_marco I'll look into those, thanks!
@00wheelie0015 күн бұрын
Irrelevant for financial (accounting) data: you are never ever going to have an irrational monetary amount ever. That said, there is plenty of financial models that do not need this accuracy and are much much faster with floating point math vs fixed point math, because of available hardware. But even then you always have to be carefull of accumulating errors; especially if you are adding large and very small number together.
@dlbiggins15 күн бұрын
It's a bit misleading to present this as a specifically Python solution. Almost all languages have variations on Decimal/Money types available either natively or as libraries.
@Carberra15 күн бұрын
It doesn't present them as if they're the _only_ solution -- it presents them as a solution in Python. There's nothing misleading here.