• Mood:

# Sometimes modern technology is scary.

I was writing a subroutine to run on one of the coprocessors on the Cell processor, and it occurred to me that I could make things run a bit faster in a particular case by assuming that the floating point product of 0.0 and any bit pattern would always be 0.0 (at least for single-precision numbers).

Now, this isn't usually the case -- there are bit patterns that represent "not a valid number", and on a computer that does math according to the IEEE standard for floating-point arithmetic, the result of multiplying "not a valid number" and 0.0 is supposed to be "not a valid number". However, the single-precision floating-point arithmetic on the Cell's coprocessors are not designed to comply with all the niceties of the IEEE standard for this; instead, like the Cray processors of old, they're designed to go as fast as possible. So it was a reasonable conjecture that they would, in fact, simply return 0.0 for everything.

The question, then, was how to quickly get an answer that I'd trust. Google was one option, but trusting random stuff on the internet is unwise, especially when the risk is introducing a subtle and hard-to-track-down bug.

The naive answer, of course, is to test every possible input. This is the sort of thing that every computer-science freshman knows is absurd and impossible -- the number of possible inputs grows exponentially, and you can get numbers like "every possible position of every electron in the universe since the big bang" without hardly trying.

Even in this exceedingly simple case, there are 232 possible 32-bit patterns that could happen. That's a bit over four billion of them. Four billion grains of sand will overfill a 55-gallon drum. This is not really even a comprehensible number.

...

Except, wait. This is a processor with a clock speed of 3.2 billion cycles per second, and it takes probably a few dozen cycles to test each number. That's ... entirely plausible.

So I tried it.

It turned out to take it about two minutes. They are, indeed, all zero.
• #### Possibly The End (of this journal)

The end of the decade seems like a good time to close chapters that have been left open and forgotten, and this LiveJournal seems like one of those.…

• #### Creating a will for your Gmail account

Today I learned: You can set up instructions for what should happen to your Gmail account (and other Google accounts) in the event of extended…

• #### A YouTube wander (and some music recommendations)

Last night I went on a YouTube walkabout, as one does, and came across rather a good bit of music I liked that needs some more sharing. I started…

• Post a new comment

#### Error

default userpic

Your reply will be screened

Your IP address will be recorded

When you submit the form an invisible reCAPTCHA check will be performed.
You must follow the Privacy Policy and Google Terms of use.
• 12 comments
• #### Possibly The End (of this journal)

The end of the decade seems like a good time to close chapters that have been left open and forgotten, and this LiveJournal seems like one of those.…

• #### Creating a will for your Gmail account

Today I learned: You can set up instructions for what should happen to your Gmail account (and other Google accounts) in the event of extended…

• #### A YouTube wander (and some music recommendations)

Last night I went on a YouTube walkabout, as one does, and came across rather a good bit of music I liked that needs some more sharing. I started…