9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Rounding off by one
@ 2010-04-19 15:43 tlaronde
  2010-04-19 16:11 ` Martin Neubauer
  2010-04-19 18:55 ` Federico G. Benavento
  0 siblings, 2 replies; 8+ messages in thread
From: tlaronde @ 2010-04-19 15:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

While verifying that I have the same result under Plan9 than under some
Unix (NetBSD), it happens that METAFONT compiles 110 of the 125 fontes,
but hence fails on some (and it should not) with something that smells
like a round off by one error on negative integer division. There is no
problem with TeX, but TeX doesn't do the same things.

Does this ring the bells to someone? It's i386 and the very same node
used for NetBSD verification (no problem on NetBSD: everything runs and
passes the test; but it was not the primary target).

Of course, it's under APE but there is no POSIX thing around: it's C89
and it even doesn't use math.h routines.

On NetBSD, the binaries are not linked against libm (whatever flavour).
Are there something "float" going under the cover?

Apparently, the APE wrapper pulls some optimization. Should I try to
look in this area?

There are conditionnals too (pre-processor: INIT, STAT etc.). Is there
problems under APE with -DINIT declarations?

There is also a suicide: divide by zero in a portion of the code doing
scaled integer arithmetic, but I think all this is linked.

If nobody has a clue, I will try to dive in the guts of METAFONT to
debug. But if I could spare some hours...

--
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 15:43 [9fans] Rounding off by one tlaronde
@ 2010-04-19 16:11 ` Martin Neubauer
  2010-04-19 18:15   ` tlaronde
  2010-04-19 18:55 ` Federico G. Benavento
  1 sibling, 1 reply; 8+ messages in thread
From: Martin Neubauer @ 2010-04-19 16:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

* tlaronde@polynum.com (tlaronde@polynum.com) wrote:
> While verifying that I have the same result under Plan9 than under some
> Unix (NetBSD), it happens that METAFONT compiles 110 of the 125 fontes,
> but hence fails on some (and it should not) with something that smells
> like a round off by one error on negative integer division. There is no
> problem with TeX, but TeX doesn't do the same things.
This might not be related to your problem, but during the recent
discussion of Plan 9's future /sys/src/cmd/cc/c99 was mentioned.
Reference 25 (in section "Not done") at least seems to be a good
candidate for a test case between Plan 9 and NetBSD compilers.

Good luck,
	Martin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 16:11 ` Martin Neubauer
@ 2010-04-19 18:15   ` tlaronde
  2010-04-19 18:26     ` tlaronde
  0 siblings, 1 reply; 8+ messages in thread
From: tlaronde @ 2010-04-19 18:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Apr 19, 2010 at 06:11:43PM +0200, Martin Neubauer wrote:
> * tlaronde@polynum.com (tlaronde@polynum.com) wrote:
> > While verifying that I have the same result under Plan9 than under some
> > Unix (NetBSD), it happens that METAFONT compiles 110 of the 125 fontes,
> > but hence fails on some (and it should not) with something that smells
> > like a round off by one error on negative integer division. There is no
> > problem with TeX, but TeX doesn't do the same things.
> This might not be related to your problem, but during the recent
> discussion of Plan 9's future /sys/src/cmd/cc/c99 was mentioned.
> Reference 25 (in section "Not done") at least seems to be a good
> candidate for a test case between Plan 9 and NetBSD compilers.

Thanks for the note. But I think I have found the problem: a division by
2 supposed to be "floor" and that slips as (x + y) / 2: is there
anything that guarantees that the result shall be floor, ceil or
nearest? I find nothing in C89.

If this is the case, (x + y) >> 1 will be the solution (suggested by
Donald E. Knuth in the METAFONTbook by the way), and that could be an
explanation of why it works with gcc, because it optimizes this.

I hope this is it, since I will finally be able to publish...

Cheers,
--
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 18:15   ` tlaronde
@ 2010-04-19 18:26     ` tlaronde
  0 siblings, 0 replies; 8+ messages in thread
From: tlaronde @ 2010-04-19 18:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Apr 19, 2010 at 08:15:33PM +0200, tlaronde@polynum.com wrote:
>
> Thanks for the note. But I think I have found the problem: a division by
> 2 supposed to be "floor" and that slips as (x + y) / 2: is there
> anything that guarantees that the result shall be floor, ceil or
> nearest? I find nothing in C89.

Replying to myself: K&R, C, A7.6 Multiplicative operators.

=> The problem is with negatives for which there is only a general rule.

--
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 15:43 [9fans] Rounding off by one tlaronde
  2010-04-19 16:11 ` Martin Neubauer
@ 2010-04-19 18:55 ` Federico G. Benavento
  2010-04-19 19:03   ` erik quanstrom
  1 sibling, 1 reply; 8+ messages in thread
From: Federico G. Benavento @ 2010-04-19 18:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

check getfcr(2)

 http://plan9.bell-labs.com/magic/man2html?man=getfcr&sect=2

it's in lib9.h for ape

--
Federico G. Benavento



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 18:55 ` Federico G. Benavento
@ 2010-04-19 19:03   ` erik quanstrom
  2010-04-19 19:14     ` Federico G. Benavento
  2010-04-19 19:28     ` tlaronde
  0 siblings, 2 replies; 8+ messages in thread
From: erik quanstrom @ 2010-04-19 19:03 UTC (permalink / raw)
  To: 9fans

On Mon Apr 19 14:57:02 EDT 2010, benavento@gmail.com wrote:
> check getfcr(2)
>
>  http://plan9.bell-labs.com/magic/man2html?man=getfcr&sect=2
>
> it's in lib9.h for ape

this doesn't apply to the integer calcuations in question.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 19:03   ` erik quanstrom
@ 2010-04-19 19:14     ` Federico G. Benavento
  2010-04-19 19:28     ` tlaronde
  1 sibling, 0 replies; 8+ messages in thread
From: Federico G. Benavento @ 2010-04-19 19:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

ok, then

On Mon, Apr 19, 2010 at 4:03 PM, erik quanstrom <quanstro@quanstro.net> wrote:
> On Mon Apr 19 14:57:02 EDT 2010, benavento@gmail.com wrote:
>> check getfcr(2)
>>
>>  http://plan9.bell-labs.com/magic/man2html?man=getfcr&sect=2
>>
>> it's in lib9.h for ape
>
> this doesn't apply to the integer calcuations in question.
>
> - erik
>
>



-- 
Federico G. Benavento



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] Rounding off by one
  2010-04-19 19:03   ` erik quanstrom
  2010-04-19 19:14     ` Federico G. Benavento
@ 2010-04-19 19:28     ` tlaronde
  1 sibling, 0 replies; 8+ messages in thread
From: tlaronde @ 2010-04-19 19:28 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Apr 19, 2010 at 03:03:19PM -0400, erik quanstrom wrote:
> On Mon Apr 19 14:57:02 EDT 2010, benavento@gmail.com wrote:
> > check getfcr(2)
> >
> >  http://plan9.bell-labs.com/magic/man2html?man=getfcr&sect=2
> >
> > it's in lib9.h for ape
>
> this doesn't apply to the integer calcuations in question.

Nonetheless, thanks for the tips, guys! but I think I have found:

-7 / 2		yields -3

(symetric of 7 / 2, but no guarante from C for negatives) while:

-7 >> 1		yields -4

(floor, what is wanted by METAFONT).

Uh!
--
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                      http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-04-19 19:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-19 15:43 [9fans] Rounding off by one tlaronde
2010-04-19 16:11 ` Martin Neubauer
2010-04-19 18:15   ` tlaronde
2010-04-19 18:26     ` tlaronde
2010-04-19 18:55 ` Federico G. Benavento
2010-04-19 19:03   ` erik quanstrom
2010-04-19 19:14     ` Federico G. Benavento
2010-04-19 19:28     ` tlaronde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).