On Fri Feb 21, 2025 at 11:41 PM CET, G. Branden Robinson wrote: > I further observe that a loss of precision threatens. > > $ cat EXPERIMENTS/unit-conversion.groff > .nf > .nr basic-units-per-cm 1c > There are \n[basic-units-per-cm] basic units per centimeter. > The line length is \n[.l] basic units. > .nr line-length-in-cm \n[.l]/1c > The line length is \n[line-length-in-cm]\~cm. > $ groff -a EXPERIMENTS/unit-conversion.groff > <beginning of page> > There are 28346 basic units per centimeter. > The line length is 468000 basic units. > The line length is 16 cm. > > That's pretty coarse. The default line length on the PostScript device > is 6.5 inches (468000u), and at 2.54cm per inch, the true line length is > closer to 16.51cm. > > The usual remedy in this situations is to use scaled integer arithmetic, > multipling all quantities of interest by a factor (often a power of ten) > sufficient to preserve the desired precision through division > operations. > > [...] > > The "Numeric expressions" section of the groff(7) man page is worth > review when considering the possibilities and limitations of arithmetic > in the groff language. (Our Texinfo manual covers the same material.) > Among other things, it notes that division truncates rather than > rounding. > [...]
By the way, Heirloom troff has floating point registers. ~ onf