# HP Forums

Full Version: Overflow challenge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hi all,

The goal of this challenge is to generate a floating point overflow in the minimum possible number of key strokes.

There are two variations, the first disallows any digit keys (inlcuding A-F if we're in hexdecimal mode), "." and EEX (or equivalent). The second allows these.

Assume that the calculator in question is in a "memory lost" power on state with no modules.

You must count any shift keys used.

You must generate an overflow not any other form of error.

```MODEL     # without numbers    # with numbers
12c              10                  4
15c               4                  3
16c               8
28s               6                  3
32sii             6                  4
35                5                  3
41                6                  4
42s               6                  4
48sx              9                  4
49g+              13                 4
```

I don't remember why I didn't work out a sequence for the 16c allowing digits.

- Pauli

Edited: 2 Sept 2006, 3:58 a.m.

Don't look at these if you want to have a go first.

However, do try to beat these.

```

```

All of the digited versions basically amount to EEX 9 10^x with appropriate key renaming, menu access and a shift before the 10^x if required. The sole exception is the 28s where 0 shift 1/x does the trick.

On to the digitless versions which are more interesting:

```12c      g e^x five times
or     g e^x thrice then ENTER ENTER y^x y^x
15c      g COS-1 10^x 10^x
16c      f NOT f SR ENTER f FLOAT 9
this one starts in integer mode and I specified a real overflow.
28s      shift STACK NEXT DEPTH shift 1/x
32sii    f ACOS f 10^x f 10^x
or     f ACOS ENTER ENTER y^x y^x
35       e^x five times
41       shift COS-1 shift 10^x shift 10^x
42s      g COS-1 shift 10^x shift 10^x
48sx     PRG STK DEPTH f ACOS f 10^x f 10^x
49g+     f PRG STACK NXT DEPTH f ACOS f 10^x f 10^x f 10^x
```

The RPL models really lose out here starting with an empty stack.

- Pauli

LOL - I just have to have a go!

HP12C - E+, E+, E+, g, n!, g, n!, g, n! - 9 keystrokes.. (no numbers)

HP25/HP33C - g, COS-1, g, 10x, g, 10x - 6 keystrokes.. (no numbers)

I don't think I can do any better than the following though!

HP32E - E+, g, Q-1 - 3 keystrokes (no numbers)

Mike T.

As an afterthought

HP11C - g, COS-1, f, n! - 4 Keystrokes (no numbers), still can't better the HP32E though...

Mike T.

How about a negative overflow ? :-)

4 keystrokes on the HP-15C, with or without numeric keys, and without using CHS of course. :-)

Best regards from, V.

The sequence

```EEX     ; enter exponent
50      ; we now have 1 x 10 ^ 50 in X
E+      ; Sigma (summations) causes overflow (1 x 10 ^ 100)
; in R6, which holds the sums of the squares of the
; successive x values
```

produces the Overflow error on the HP 25, with "OF" on the display, a specific error message for register arithmetic overflow.

The sequence

```EEX     ; enter exponent
50      ; we now have 1 x 10 ^ 50 in X
x2      ; square X => 1 x 10 ^ 100
```

produces just 9.9999999 E 99, but not "OF" nor "Error" messages.

On many models this should do (without entering any data)...

```ACOS
TAN
```

It takes four keystrokes on most models, but just three keystrokes on those where trig functions were not shifted (i.e.: HP35, 45, 21, 41C)...

Valentín:

How about LOG (or, for that matter, LN)?

Would you consider it an overflow, or just a mathematical misconcept?

Best regards,

Andrés

Hi, Andrés:

Andrés posted:

"How about LOG (or, for that matter, LN)?"

Well, on my HP-15C both give just Error 0 instead of overflow (9.999...E99 or -9.999...E99, or the particular overflow value for other HP machines allowing for wider numeric range), so I guess this doesn't cut it.

Probably it will be the same on most HP calcs having LOG/LN functions. Thanks anyway for you input and

Best regards from V.

Older machines (pre HP41) were not so discerning :-)

Again, the answer will look as overflow on older machines, but newer models may show "invalid data" when asked about the tangent of a 90 degrees angle. So my previous answer is not a strict overflow, I regret...

On the 48G (probably the same for GX/S/SX), I found this one (without numers):

Lshift PI Lshift ->Num Lshift 10^x Lshift 10^x

That is 8 keys instead of 9.

Even the Lshift ->Num can be saved provided that the calc is in full numerical mode (-2 SF), but this is not "Memory Lost" condition.

No I'd say that for the earlier models (HP2x, 3x, and 10x) ACOS,TAN fits the criteria nicely, and in just 3/4 key strokes too (just wish I'd thought of it).
I'd assumed that like LOG(0) and LN(0) TAN(90) would return an 'Error 0'..

MIke T.

Yes they were, I just checked my HP33C, HP32E and HP11C and on all of them LOG(0) or LN(0) results in 'Error 0' instead of '9.999999 99', even the HP21 returns 'Error'. These are all pre HP41 models (I think), so based on this I'd say that LOG(0) doesn't fit the criteria.

Mike T.

Well, with the 48 and 49 series, in some cases you have a choice.

By default (flags -20, -21, and -22 clear):

An underflow returns 0.

An overflow with any argument "real" returns 999999999999E499 or
-999999999999E499

With any argument real, operations such as 0 LOG, 0 LN, -1 !, or
division of a non-zero by zero cause an "Infinite Result" error.

With flag -20 set, an underflow causes a "Positive Underflow" or
"Negative Underflow" error.

With flag -21 set, with any argument real, an overflow causes an
"Overflow" error, without distinguishing whether positive or
negative.

With flag -22 set, with any argument real, 0 LOG, 0 LN, and -1 !
return -999999999999E499, and division of a non-zero by 0 returns
999999999999E499 or -999999999999E499.

Regardless of the state of these flags:

With either argument real, 0 divided by 0 causes an "Undefined
result" error.

With all arguments exact (49 series only), 0 LOG and 0 LN return
the negative of the infinity function (represented by the infinity
symbol) within an algebraic. Operations such as -1 ! or division
of a non-zero by 0 return the infinity function within an
algebraic. 0 divided by 0 returns the undefined function
(represented by the ? symbol) within an algebraic. Most operations
with infinity seem to simply return infinity, but I've noticed
that infinity minus infinity or -inifinity plus infinity return
undefined. As far as I've noticed, operations with undefined
simply return undefined.

Some of these results may well depend on the state of various
other flags too.

The 49 series, with all arguments exact, also adds an "Integer too
large" error, I guess for cases where the calculator won't have
enough memory available for the resulting integer.

Regards,
James

`32SII:      Rshif   ->°F   ex   ex  `

Quote:
41 shift COS-1 shift 10^x shift 10^x

Slightly better on the 41: 5 keystrokes, no numbers.

```1 shift  2 ACOS  3 ENTER  4 shift  5 Y^X
```

Greetings,
Massimo

Edited: 2 Sept 2006, 8:41 p.m.

`12C: g ex g 12x g 12x g n!`

Quote:
How about a negative overflow ? :-)

4 keystrokes on the HP-15C, with or without numeric keys, and without using CHS of course. :-)

Very nice.

I suspect you're thinking of "g simga- f x!" but I could be wrong.

- Pauli

I am quite amazed by the variety of solutions posted so quickly.

I'm not amazed that the majority of my attempts were easily surpassed.

It is going to be hard to beat ARCCOS TAN on most units.

- Pauli

Hi. Paul:

Paul posted:

"I suspect you're thinking of "g simga- f x!" but I could be wrong."

But then you're not, that's the exact solution I originally came up with ! :-)

Though by the way, it's spelled "sigma", not "simga", which, if repeated emphatically and with a certain rythm to it, seems directly taken out from some old "Tarzan" movie :-)

Best regards from V.

- Pauli

12C: g Sigma- g 12x Enter Enter * g n! *

10 keystrokes, no numbers.

sigma+ ENTER %T g n!

5 keystrokes

That's the record so far for 'positive' overflow. Anyway, your approach is fine:

g Sigma- ENTER %T g n! *

7 keystrokes, no number. Again, a record!

If you want negative overflow just add CHS to my earlier effort! Six keystrokes. Or is that cheating?

Well, Paul Dale has not said anything about CHS. Valentin has. But since '.' and 'EEX' were considered numeric keys, CHS should be included in the group, shouldn't it?

Edited: 3 Sept 2006, 6:19 p.m.

Seems fair enough!

Here's a bizarre *four* keystroke solution to positive overflow that works on my 12C but YMMV. :-)

R/S (wait for three flashes of running) R/S y^x y^x.

I'd have to say that using CHS to turn a positive overflow negative is cheating. The CHS operation isn't the cause of the overflow after all.

- Pauli

For the 12C or others?:

9 ENTER 9 y^x g e^x

Six steps.

or...

231 g e^x

Five steps.

Neat challenge.

Tony

or...

70 g n!

Four steps

OK, 12c no numbers or EEX:

Sigma+ g e^x g e^x g e^x g e^x

Tony

Here's a shorter one for the 12c using no numbers. It's a bit creepy. ;)

f P/R g e^x f P/R R/S

Seven steps.

Tony

[I'll edit this message to include new results rather than reposting the summary in full, sorry if this confuses anyone]

Okay a summary of the results so far.
The RPL machines in particular should still be beatable.

For the base challenge of generating afloating point overflow without using number keys:

```MODEL     # without numbers  sequence
12c               5          sigma+ ENTER %T g n!
14b               8          sigma+ PRC MAR shift x^2 shift MATH e^x
16c               8          f NOT f SR ENTER f FLOAT 9
17bii             6          shift MATH 10^x 10^x 10^x 10^x
20s               4          right-shift ->F e^x e^x
27s               5          e^x e^x e^x e^x e^x
28s               6          shift STACK NEXT DEPTH shift 1/x
32e               3          sigma+ g Q-1
32sii             4          sigma+ right-shift /c e^x
42s               6          g COS-1 shift 10^x shift 10^x
48gx              5          left-shift MEMORY MEM left-shift 10^X
48sx              5          left-shift MEMORY MEM left-shift 10^X
49g+              6          left-shift PRG MEM MEM left-short 10^X
11c               3          g COS-1 TAN
15c               3          g COS-1 TAN
21                3          shift COS-1 TAN
25                4          g COS-1 f TAN
33c               4          g COS-1 f TAN
34c               4          g COS-1 f TAN
35                3          arc COS TAN
41                3          shift COS-1 TAN
45                3          shift COS-1 TAN
```

For the overflow challenge when digits are allowed (where they produce a shorter sequence than without digits):

```MODEL     # with numbers     sequence
12c               4          9 9 g n!
28s               3          0 shift 1/x
48sx              4          EEX 9 left-shift 10^X
49g+              4          EEX 9 left-shift 10^X
```

And a couple of negative overflow versions:

```15c               4          g sigma- f x!
34c               4          g sigma- h x!
```

- Pauli

Edited: 6 Sept 2006, 1:29 a.m. after one or more responses were posted

While I'm glad that my candidate (ACOS TAN) was a winner for some older calculators (I don't have all of them to test), I must say that such sequence produces Out of Range on the HP42S and Invalid Data on the HP32Sii. Such messages may not qualify as an Overflow condition for this challenge. In some models (I think that the HP41C is included, perhaps one of the latest to behave in such a way), my candidate gives 9.999999999 E99.

Hello Andrés,

Quote:
In some models (I think that the HP41C is included, perhaps one of the latest to behave in such a way), my candidate gives 9.999999999 E99.

You are right about the 41C, that's why I had to use 5 steps to make it show "OUT OF RANGE".

Greetings,
Massimo

48GX: LShift MEMORY MEM LShift 10^X for five keystrokes.

And if something similar doesn't work on the 48SX, there's

LShift pi LShift ->NUM LShift 10^x LShift 10^x for eight keystrokes without digits.

The 16C doesn't have a 10^x function, precluding the generic digited solution. But this works:

f EEX 5 0 ENTER * for six keystrokes with digits, starting and ending in real mode.

This one was very smart... I didn't think about it.

Thanks.

I mean: the MEM one.

Drat, didn't verify that sequence on all models :-(

- Pauli

Thanks for this. Similar works for the 48sx and the 49g+.

- Pauli

Edited: 7 Sept 2006, 11:18 p.m.

I just realized something: If we're truly in the "memory lost" state, many of these solutions will not work since the first keystroke has no effect but to clear the message.

But ignoring that and moving on... For the negative overflow, for those machines on which the ARCCOS, TAN produce a positive overflow, then ARCCOS, -, TAN will produce a negative overflow.

A MUCH harder challenge is to get the smallest representable positive number (1E-99 or 1E-499, depending on model), or similarly, the largest representable negative number (-1E-99 or -1E-499).

With digits, I don't think you can beat 1, EEX, CHS, 9, 9. But without digits...?

You didn't include Gerson's 4 keystroke 32SII solution. Here's another 4-keyer:

32SII: sigma+, right-shift, /c, e^x.

Here are some other calculators:

27S: e^x, e^x, e^x, e^x, e^x (5 keystrokes)

20S: right-shift, -->F, e^x, e^x (4 keystrokes)

17BII: shift, MATH, 10^x, 10^x, 10^x, 10^x (6 keystrokes)

and the very challenging

14B: sigma+, PRC, MAR, shift, x^2, shift, MATH, e^x (8 keystrokes)

All in now, thanks for these.

- Pauli

Quote:
With digits, I don't think you can beat 1, EEX, CHS, 9, 9.

Of course you can! Just leave out the "1" and start with EEX.

Hi, Kiyoshi Akima:

You posted:

"A MUCH harder challenge is to get the smallest representable positive number (1E-99 or 1E-499, depending on model)"

In the HP-71B, the smallest representable positive number is neither 1E-99 not 1E-499 but 1E-510, and it's trivially obtainable, namely:
```   >MINREAL
0.00000000001E-499
```
though I don't claim that this is the minimum keystroke solution, it's only for informational purposes.
Best regards from V.

Here is my solution for the 12c (tried on a platinum):

```key          X        Y       R1
---------------------------------
Sigma+       1        0        1
ENTER        1        1        1
%T         100        1        1
STO - 1    100        1      -99
g Sqrt      10        1      -99
RCL 1      -99       10      -99
y^x      1E-99        1      -99
```

I count 11 keystrokes. I assume that's not the last word on this issue.

You may say that I used the digit "1" to access the register R1. Is this cheating?

Marcus

Here is another solution for the 12c (tried on a platinum). It does not use the digit "1" for register access:

```key          X        Y
-----------------------
Sigma+       1        0
ENTER        1        1
%T         100        1
-          -99        0
g LSTx     100      -99
g Sqrt      10      -99
x<>y       -99       10
y^x      1E-99        0
```

This is just 10 keystrokes.

Marcus

Edited: 6 Sept 2006, 5:36 a.m.

Quote:
Here is another solution for the 12c (tried on a platinum). It does not use the digit "1" for register access:
```key          X        Y
-----------------------
Sigma+       1        0
ENTER        1        1
%T         100        1
-          -99        0
g LSTx     100      -99
g Sqrt      10      -99
x<>y       -99       10
y^x      1E-99        0
```

Nice try but this is an exact calculation of 1E-99
not an underflow. Underflow on the 12C is simply zero as demonstrated by:
`1E-55 ENTER *`

Quote:
Nice try but this is an exact calculation of 1E-99 not an underflow.

The original question was to do just that:

Quote:
A MUCH harder challenge is to get the smallest representable positive number (1E-99 or 1E-499, depending on model)...

Marcus

Rather convoluted, but no data entry (Pi, EEX and CHS may be considered data entry):

```GRAD     ; choose angular mode
ACOS     ; acos(0)   x = 100
DSE ST X ; decrement x to 99
10 ^ x   ; antilog,  x = 1 E  99
1 / x    ; inverse,  x = 1 E -99
DEG      ; just to be polite...
```

I think it only makes sense on the 41C, becsuse it has the DSE functions for the stack but doesn´t allows for exponents greater than 99. Previous models don´t have DSE ST X; later models as the 42S have such instruction, but also allow for greater exponents and then the smallest number is not 1E-99 on those models.

I don't believe I typed that "1" (Hits himself upside the head.) :-)

Using a digit key to access a register isn't cheating, no more than using a shifted digit key to access some function.

Here's what I came up with on the 11C without digits: 10^x, 10^x, ENTER, 10^x, 10^x, /, for six keystrokes. The same sequence works on the 15C but only leaves the result in the display half the time.

On the RPL machines, there's a solution similar to the one V put forth for the 71B but one fewer keystroke: <press and hold down alpha>, M, I, N, R, <release alpha> LShift, ->NUM.

Incidentally, my Emu71 says "WRN: Underflow" and gives me zero instead of a small positive number. Maybe I just don't have it master cleared right. I get the same warning for any result less than 1E-499. Are you sure MINREAL is the smallest representable real number and not the smallest difference between two real numbers?

The 16C is a hard one, without e^x, 10^x, or any of the other conventional ways to get a 10 or even a 1 onto the stack. The best I've come up with so far: f, NOT, f, SR, ENTER, f, FLOAT, 9, ENTER, ENTER, /, ENTER, +, ENTER, ENTER, +, ENTER, +, +, x<>y, /, for twenty-one keystrokes.

Hi, Kiyoshi Akima:

You posted:

"Are you sure MINREAL is the smallest representable real number and not the smallest difference between two real numbers?"

As you're replying to your own previous post and I don't think you're asking that question to yourself, I'll boldly assume your question is actually intended for me (or someone else except yourself).

That being the case the answer is yes, MINREAL is the smallest representable real number in the HP-71B, which in compliancy with the IEEE standard which it fully implements (but perhaps the 48/49 RPL models do not), allows for partially denormalized values at the extremes of the particular numerical range, so you can have
values as 1E-499, 0.1E-499, 0.000230056E-499, until you reach the value of MINREAL:

```    >MINREAL
0.00000000001E-499
```
which is indeed maximally denormalized and the smallest representable real number. You can, of course, operate with it, apart from displaying it:
```    >MINREAL+MINREAL
0.00000000002E-499
```
I'm not sure but it might be the case that 48/49 machines do not allow for this partial denormalization to extend the available range, perhaps it depends on some dreadfully obscure flag settings, as most everything does in those machines. Time to put apart the graphic toys and switch to serious math devices :-)

Best regards from V.

So what do I have to do to clear the HP-71B (or Emu71)? I apparently have some dreadfully obscure flag settings wrong. As I stated, MINREAL gives me an underflow warning and produces the value zero, not a small positive number.

Edited: 6 Sept 2006, 7:18 p.m.

On my 71b (without maths rom) I enter MINREAL and get "WRN:Underflow" followed, after a pause, by "0"

- Pauli

Hi, Paul:

Paul posted:

"On my 71b (without maths rom) I enter MINREAL and get "WRN:Underflow" followed, after a pause, by "0""

First of all, if you have a "71b (without maths rom)" then you don't actually have an HP-71B but the crippled, maimed version the bean counters at HP decided to release instead at the time. Go get a Math ROM (or use Emu71, which already includes it) and then you're in business. That said, MINREAL behaviour has nothing to do with the Math ROM being present or not, but get one anyway :-)

Then about your statement, notice that I say in my original post that "I don't claim that this is the minimum keystroke solution, it's only for informational purposes". This is because the original challenge explicitly requests that the starting point is a factory-reset machine ("Memory Lost"), and after such a memory reset, the HP-71B is left in DEFAULT ON mode, which specifies that
mathematical exceptions (such as division by zero, overflow, underflow, etc), are to result in a warning message being issued, plus a default value automatically supplied for the offending operation, then the computation or program resumes using that default value instead.

So, in the factory-reset DEFAULT ON mode, you would get this:

```    >DEFAULT ON
>MINREAL
WRN:Underflow
0
```
i.e., a message is displayed warning of the underflow (as MINREAL is less than 1E-499), a "0" is reported as the result, and your
computation or program proceeds using it.

If you'd rather have no default values supplied but a hard error being reported instead (which would perhaps be specially desirable for Division by Zero or Overflow exceptions), you specify DEFAULT OFF instead, in which case you'll get this:

```    >DEFAULT OFF
>MINREAL
ERR:Underflow
```
and, as you may see, you'll get an ERRor message (not a WaRNing),
no default value is supplied (no "0" output this time) and your computation or program would stop at once (unless the error was caught by an ON ERROR statement, but that's another story ...)

Fortunately, the HP-71B (even your maimed version) does implement full IEEE compliance, and that includes gradual denormalization of values at the extremes of the representable range, and in the case of the Underflow exception, values as low as MINREAL ( 0.00000000001E-499) can thus be used if necessary. As this is an extension to the usual, non-IEEE behavior, the user is given the decision to allow for this extension or not. If you'd like to turn on this extension by default, you simply specify DEFAULT EXTEND,
like this:

```    >DEFAULT EXTEND
>MINREAL
0.00000000001E-499
```
and, as you may see, this time there are no warning or error messages, and no default value is supplied but the actual, denormalized value of MINREAL, which you can further use in computations.

There's much more to this topic about DEFAULT exception handling
modes and TRAP settings, a good place to start are the "Math Exceptions" section (HP-71B's Owner's Handbook pp. 57 and following) and the entries for DEFAULT, TRAP, and MINREAL in the Reference Manual.

In any case, take note that I didn't say that my posting was to be considered as an entry to the 'challenge', which it isn't, but merely to point out the fact than in the HP-71B, 1E-499 is not the smallest representable value, that would be MINREAL. If you'd rather have the smallest representable normalized value, use EPS instead. That would be 1E-499.

Best regards from V.

Hi, Kiyoshi Akima:

You posted:

"So what do I have to do to clear the HP-71B (or Emu71)? I apparently have some dreadfully obscure flag settings wrong. As I stated, MINREAL gives me an
underflow warning and produces the value zero, not a small positive number".

To avoid repeating twice the same explanation, please have a look at my message #44 in reply to Paul Dale's message #43, a little above in this same thread.

As for your ironic "I apparently have some dreadfully obscure flag settings wrong", which I take to be a lame attempt at humor, well, if you consider issuing a DEFAULT EXTEND statement to extend the default math exception behavior as something "dreadfully obscure" then it seems to me you haven't read your HP-71B Owner's Manual much, if at all.

Best regards from V.

Quite right. Sorry for taking you to task. For some reason, I was expecting underflow to remain at 1E-99 in the display (to act as a warning to the user) and that distracted me from the real question.

Since I have neither an HP71B nor its manual(s), you're right, I haven't read the manual(s) very much.

The "dreadfully obscure flag settings" comment was simply a quote of your presumed attempt at humor. Since all the flag settings are visible and alterable via RShift MODES FLAG, I don't consider them any more obscure than a statement and a keyword that has to be memorized. That's juat an opinion, of course. But then, since I haven't read the manual(s), perhaps there is a way to have the machine jog my memory and I'm simply ignorant of it.

Hi, Kiyoshi Akima:

You posted:

"Since I have neither an HP71B nor its manual(s), you're right, I haven't read the manual(s) very much."

I thought so.

"The "dreadfully obscure flag settings" comment was simply a quote of your presumed attempt at humor."

Thanks for your explanation but I did recognize the quote. And you presumed wrong, my original statement wasn't any attempt at humor whatsoever but a serious opinion. Whenever I want something to be taken lightly, I append an smiley to it, like this :-)

But all of this has nothing to do with HP calculators, more like some damaged ego and such so I won't further waste my time. Should you feel the irresistible urge to have the last word, go ahead.

Best regards from V.

Thanks for the explanation.

Unfortunately, I've neither the maths rom nor the user manual for my 17b :-( I'm keeping an eye out for these but they don't seem to be terribly common.

- Pauli

Hi, Paul --

Quote:
Unfortunately, I've neither the HP-71B maths rom nor the user manual for my 17b (71B?) :-( I'm keeping an eye out for these but they don't seem to be terribly common.

As of several years ago, I'd never seen an HP-71B Math ROM on US eBay or the MoHPC classifieds. After I mentioned this, a Forum participant was generous enough to sell me one, with manual.

In the past year, I've seen four Math ROM's sold on US eBay, but all without manuals. (A scan of the manual is available on the MoHPC CD/DVD set.) The ROM's each sold for less than US\$150.

The HP-71B manual sets are commonly available on US eBay for reasonable prices.

-- KS

Unfortunately, US Ebay isn't always good for those who don't live in North America. Many sellers won't post internationally :-(

- Pauli