News for hackers. Stuff that matters.
Re:SVG passthrough precision by PaulHoule on Monday April 18, 2022 @02:30PM (#31074607)
I was thinking that the perfect SVG editor would use arbitrary-precision decimal math so that you'd never run into those 0.1 + 0.2 != 0.3 problems that are endemic when you use those "floating point" numbers that are approximate to those phony "real" numbers Cantor warned you about.

(Baudrillard would say that anybody using the word "real" is trying to bind you with illusion and like a wolf that craps on a trap to protect the pack he crapped on that word pretty bad!)

Re:SVG passthrough precision by legulere on Monday April 18, 2022 @04:57PM (#31076441)
The question is what you try to achieve. At a certain precision you won't get any difference in any rasterized image anymore so you do not really care anymore. The SVG standard agrees there and states that 32 bit floating point is enough. IEEE binary floating point numbers are widely supported and performant.

You can easily sidestep problems with errors of calculation (which includes already parsing decimal floats into binary floats, and happens here also with addition) by keeping the error smaller than what you care about: Read in as double precision float and use double for calculation, convert back to single precision before converting to decimal floating point. The error you will do in double precision will be smaller than what you loose converting to single precision. You can use that for SVG path optimization where you will run across 0.1+0.2!=0.3 problems.

If you really want exact measurements, then you would want fractional numbers, so you can also cut lengths in e.g. three precisely.

Re:SVG passthrough precision by makapuf on Tuesday April 19, 2022 @02:28AM (#31080193)
What if I want a square of area exactly two? Or an angle of 27° precisely? I will be difficult to have _exact_ measurements anyway.
Re:SVG passthrough precision by legulere on Tuesday April 19, 2022 @05:34AM (#31081156)
Then you need symbolic math
Re:SVG passthrough precision by 3r3rni9 on Monday April 18, 2022 @03:50PM (#31075572)
Came here to mention this, seeing those high precision decimals -- if you ever need to use their dimensions in any DOM arethmetic, be sure your process converts those to integers and back first (or use a lib like BigNumber, or the new JS BigInt). Many experienced front end devs ignore floating point issues unless they're doing financial math, then wonder why their JavaScript CSS calculations won't work out precicely.
Re:SVG passthrough precision by PaulHoule on Monday April 18, 2022 @04:35PM (#31076148)
In the case of the SVG editor I'd really like something that round-trips to and from SVG that looks nice in a text editor.

In a case like that it should "snap-to-grid" on the last decimal place of the number that's being edited, maybe the grid should even be displayed on the screen. That grid might be rotated or skewed because of coordinate transforms, and there ought to be some way to add another digit worth of fineness if not a factor of 2 or 5.

Re:SVG passthrough precision by a9h74j on Monday April 18, 2022 @08:33PM (#31078494)
You might enjoy this proposal for DEC64:

https://www.crockford.com/dec64.html

IMHO it would be nice to see it used in larger-integer-presenting domains: with some limitations, accounting; interpreters where you want 0.1 + 0.2 == 0.3; anywhere there are measurements with units, and factor-of-ten scaling of finite digits is helpful; anywhere you want the simplicity of a single number-type and number-builder; possibly where you want to reserve some exponents for giving language keywords orthogonal number representations.