5 ms·
Are there any mainstream languages that consider a decimal number to be a primitive type? I feel like floating point numbers are far less meaningful in every da
by seanalltogether 8y ago
Are there any mainstream languages that consider a decimal number to be a primitive type? I feel like floating point numbers are far less meaningful in every day programs. Even 2d graphics would be easier with decimal numbers. Unless you're using numbers that scale from very small to very large, like 3d games or scientific calculations, you don't actually want to use floating point.
- deleted 8y ago[deleted]
- mschuetz 8y ago> Are there any mainstream languages that consider a decimal number to be a primitive type Mathematica. But it's not particularely fast. > Unless you're using numbers that scale from very small to very large, like 3d games or scientific calculations, you don't actually want to use floating point. Unfortunately, we can sometimes only use floats in 3D graphics and floats aren't even good for semi-large to large 3D scenes. Unity is a particular bad offender. It's not even necessary for meshes but having double precision transformation matrices would make life so much easier. Could simply use double precision world and view matrices, then multiply them together and the large terms would cancel out in the resulting worldView matrix, which can then by cast back to single precision floats.
- MauranKilom 8y agoNot to mention z-fighting for distant objects.
- misterdoubt 8y agoDepends how you define 'primitive type.' A decimal number is built-in for C# and comes along with the standard libraries of Ruby, Python, Java, at least.
- lozenge 8y agoCobol?
- twtw 8y agoJulia has built in rationals (as do a few other languages). I'm not aware of any language (other than Wolfram) that defaults to storing something like 0.1 as 1/10 - i.e. uses the decimal constant notation for rationals, rather than having some secondary syntax or library.
- rurban 8y agoIn Common Lisp it's even standardized. Arithmetic is too important to be left to wrong CPU intrinsics.
- kccqzy 8y agoEven in Wolfram, 0.1 is not the same as 1/10. In[1]:= Precision[0.1] Out[1]= MachinePrecision In[2]:= Precision[1/10] Out[2]= \[Infinity]
- twtw 8y agoAh, thanks for the correction. I don't currently have a license, so out of curiosity is 0.3 == 3/10 in wolfram?
- kccqzy 8y agoYes that's true. According to the documentation of Equal†, > Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits). Which is why in Mathematica, 0.1+0.2==0.3 is also True. If you need a kind of equality comparison that returns False for 0.3 and 3/10, use SameQ. Funnily, SameQ[0.1+0.2,0.3] is also True, because SameQ allows two machine precision numbers to differ in their last binary digit. †: https://reference.wolfram.com/language/ref/Equal.html https://reference.wolfram.com/language/ref/Equal.html
- sgt101 8y agoYes, but the Julia REPL produces 2.0 as an answer and casting both these to BigInt doesn't work either.
- jimhefferon 8y agoRacket: https://docs.racket-lang.org/guide/numbers.html https://docs.racket-lang.org/guide/numbers.html
- lalaithion 8y agoThere are plenty of languages without the concept of a primitive type...
- ummonk 8y agoDo you mean some fixed point decimal number? Cause the normal way to do decimal numbers would still be floating point.
- derefr 8y agoThey mean arbitrary-precision decimal arithmetic (i.e. a struct containing bignum x and integer y where the connoted value is x*10^y, such that multiplication can be defined simply as the independent multiplication of the value parts and of the exponent parts.)
- kccqzy 8y agoThere are issues with arbitrary precision decimal numbers. For one, you can't deal with things like 1/3: these are repeating decimals so they need infinite memory to represent.
- mongol 8y agoBc?
- softawre 8y agoC# https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/decimal https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...