The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Arthur Krewat <krewat@kilonet.net>
To: tuhs@minnie.tuhs.org
Subject: Re: [TUHS] Space Travel, was New: The Earliest UNIX Code
Date: Fri, 18 Oct 2019 19:20:35 -0400	[thread overview]
Message-ID: <9053c41b-e306-8547-50fd-207e0bfb49af@kilonet.net> (raw)
In-Reply-To: <CAG=a+rgS8iJKnd85wv5kt8JfgZNkOR0u47FySMXYvD+jsOKEZA@mail.gmail.com>



On 10/18/2019 6:04 PM, Ken Thompson via TUHS wrote:
> while writing "space travel,"
> i could not get the space ship integration
> around a planet to keep from either gaining or
> losing energy due to floating point errors.
> i asked dick hamming if he could help. after
> a couple hours, he came back with a formula.
> i tried it and it worked perfectly. it was some
> weird simple double integration that self
> corrected for fp round off. as near as i can
> ascertain, the formula was never published
> and no one i have asked (including me) has
> been able to recreate it.
>
>
This reminds me of an experiment I performed comparing speeds of x86 
assembler, and C, when I first started working in it. The experiment was 
to generate a 3D cube wireframe, and rotate it about any (or all three) 
of it's axes, moving it X degrees at a time. Simple vector math, really. 
Included perspective, so that the back-end of the wireframe cube would 
look smaller than the front side.

I had been an assembler snob, having started in MACRO-10 on a KA10 
PDP-10 in 9th grade. I always assumed assembler would be faster for 
anything, given the right amount of optimization. The assembler side of 
the experiment, I did the CGA graphics directly. I think in the C 
version, I used the built-in library that came with it. I no longer have 
the source for the C version, but I do, for the assembler version. I 
didn't have an 8087 floating point accelerator, so I wrote my assembler 
example to use two 16-bit words of integers, combining them for a 31-bit 
integer value with sign.

Timing 1000 rotations, the assembler version took X amount of time. The 
C version took X*1.5

Now mind you, the C version used real floating point, and a software 
floating point library with no hardware accelerator. At that point, I 
realized C was the way to go. It had passed my experiment with flying 
colors. The C compiler, I believe, was from Computer Innovations, 
Copyright (c)1981,82,83,84,85

The reason this is similar to Ken's statement above: In the assembler 
version, the cube would deform quite a bit before the run would finish. 
A 31-bit integer didn't accurately reflect the result of the math. Over 
time, that slight inaccuracy really added up. The accuracy of the C 
version using floats was spot on.  So while I basically cheated for the 
assembler version, causing the deformation of the cube over time, the C 
version was 100% accurate even though it was slower.

I wonder, is there something inherently different between PDP-11/7 
floats and Intel's leading to the inaccuracy Ken mentions? Was the 
PDP-11 (or the -7) floating point that much different than IEEE-754 ?

art k.


  reply	other threads:[~2019-10-18 23:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 11:52 Doug McIlroy
2019-10-18 18:36 ` Steffen Nurpmeso
2019-10-18 20:19   ` SPC
2019-10-18 22:04     ` Ken Thompson via TUHS
2019-10-18 23:20       ` Arthur Krewat [this message]
2019-10-19  0:57         ` G. Branden Robinson
2019-10-19  1:11           ` Arthur Krewat
2019-10-29  2:18       ` Lawrence Stewart
2019-10-26 15:10 ` Lars Brinkhoff
  -- strict thread matches above, loose matches on Subject: below --
2019-10-19 14:40 Doug McIlroy
2019-10-19 18:32 ` Abhinav Rajagopalan
2019-10-19 18:44   ` Abhinav Rajagopalan
2019-10-19 19:19   ` Clem Cole
2019-10-19 19:50     ` Henry Bent
2019-10-19 20:24       ` Arthur Krewat
2019-10-19 13:13 Doug McIlroy
2019-10-17 19:21 [TUHS] New: The Earliest UNIX Code - From the Collection of the Software History Center, Computer History Museum Lyle Bickley
2019-10-17 20:44 ` [TUHS] Space Travel, was New: The Earliest UNIX Code Warren Toomey
2019-10-17 22:39   ` Warner Losh
2019-10-17 22:51     ` Warren Toomey
2019-10-18  5:59       ` Lars Brinkhoff
2019-10-18  9:30         ` SPC
2019-10-18 17:36         ` Nemo
2019-10-18  3:01   ` Warren Toomey
2019-10-18  5:07   ` Lars Brinkhoff
2019-10-18  5:10     ` Lars Brinkhoff
2019-10-18 13:37       ` Warner Losh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9053c41b-e306-8547-50fd-207e0bfb49af@kilonet.net \
    --to=krewat@kilonet.net \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).