Index | Thread | Search

From:
Jörg Sonnenberger <joerg@bec.de>
Subject:
Re: exact floating point calculations in roff(7)
To:
Ingo Schwarze <schwarze@usta.de>, tech@openbsd.org
Cc:
Alexander Bluhm <alexander.bluhm@gmx.net>
Date:
Thu, 3 Apr 2025 22:13:23 +0200

Download raw body.

Thread
On 4/2/25 4:15 PM, Ingo Schwarze wrote:
> Index: roff.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mandoc/roff.c,v
> diff -u -p -r1.276 roff.c
> --- roff.c	6 Jan 2025 18:48:13 -0000	1.276
> +++ roff.c	2 Apr 2025 13:52:53 -0000
> @@ -2468,7 +2468,8 @@ roff_getnum(const char *v, int *pos, int
>   		myres *= 240.0;
>   		break;
>   	case 'c':
> -		myres *= 240.0 / 2.54;
> +		myres *= 24000.0;
> +		myres /= 254.0;
>   		break;
>   	case 'v':
>   	case 'P':

Ignoring the scaling (which shouldn't actually matter), it is still a 
functional change in C.

   a *= b;
   a *= c;

and

   a *= b * c;

are semantically different, because the C language requires rounding 
after each multiplication in the first sequence, but only one rounding 
in the second sequence. On processors with higher intermediary 
precision, this matters. With GCC, there is the additional complication 
that it defaults to ignore the compiler for performance reasons and will 
apply associativity freely with default flags under -O2.

Joerg