PDA

View Full Version : Overflow, Double Type



BlueCactus
10-28-2005, 01:59 PM
The number shown is supposedly the limit for Double. So why do I get an overflow error? If I reduce the number by 1 it works. This means I'm going to have to do a string test on imported files before converting the values to Double.
Dim k As Double
k = CDbl("1.79769313486232e308")

Zack Barresse
10-28-2005, 03:18 PM
I would assume it has to do along the lines with the whole greater than or equal to type issue. Maybe their referring to the actual limit, not what is acceptable under the limit..

MWE
10-28-2005, 05:10 PM
The number shown is supposedly the limit for Double. So why do I get an overflow error? If I reduce the number by 1 it works. This means I'm going to have to do a string test on imported files before converting the values to Double.
Dim k As Double
k = CDbl("1.79769313486232e308")

I get the same result, so it is not your specific system. In fact you do not need to do the conversion, just
Dim K as Double
K = 1.79769313486232E308
generates an immediate (while in the VB editor) overflow error.

1.79769313486232e308 is a pretty big number, do you actually expect to encounter numbers that large?

You may wish to write a special version of CDbl, perhaps CDbl2, that you can use for this application instead of CDbl. It would perform the check and do whatever housekeeping is required before returning a value of type double. It is a bit of a pain to write, but it will save you doing the check multiple times.

TonyJollans
10-29-2005, 04:04 AM
It does rather seem as though the help file is incorrect - it happens sometimes :)

What sort of data are you working with which might have this specific value but not anything bigger - which would require a specific string test for this value?

BlueCactus
10-29-2005, 08:37 AM
It does rather seem as though the help file is incorrect - it happens sometimes :)

What sort of data are you working with which might have this specific value but not anything bigger - which would require a specific string test for this value?
It's a data stream from an instrument. If the detector gets maxed out then it'll write out the max (or min) double precision value - hence the number above and my surprise that Excel can't deal with it. It's a worthless data point anyway, but the error it generates creates a problem for importing the stream into Excel. Sticking in a string test will slow down the import.

TonyJollans
10-29-2005, 03:00 PM
So how do you create the max double you write out?

The actual maximum is 1.797693134862315866881734..... but when the mantissa is rounded (for example when entering a literal into VBA) you get a number that is too big.

Can you not do a check for, say, > 1E308 rather than checking the actual limit value (which you can never specify precisely anyway)?