Long vs. Integer bug in LotusScript?

This one has been reproduced on two different machines in our office:

Dim temp as Long

temp = ( 23 * 3600 )

This code won’t even compile. Notes generates an “Overflow” error.

What appears to be going on here is that Notes is thinking that Temp is defined as an integer and is thus causing the overflow. If you enter

temp = ( 9 * 3600 )

…the code works fine. Any 2 digit number before the 3600 craps out the code with an overflow, which makes sense since 10 * 3600 = 36000, which is greater than 32767…the limit of an integer.

Can anyone else reproduce and/or explain this potential bug?

Dave

Subject: Happens to me as well. Workarounds:

tmp = Clng(23) * 3600tmp = 23. * 3600

Subject: Long vs. Integer bug in LotusScript?

The explanation is that the error is happening prior to assignment of the result to the variable. To perform the calculation, LotusScript has to decide how it will handle the math. Since both values are integers it decides to do integer arithmetic and then dies when it gets a result larger than an integer. If you clng() one of the values as Bill suggested or just make one of the values larger than an integer (i.e. 23 * 36000) then a Long calculation is performed and the result does not overflow.

Doing 23. * 3600 will also work because now your 23 is getting interpreted as a floating point number and so floating point arithmetic is performed (and both floating point types can handle the result).

Subject: RE: Long vs. Integer bug in LotusScript?

You can also just designate a constant as Long using the & suffix, e.g. 23& * 3600&

Subject: RE: Long vs. Integer bug in LotusScript?

Andre…for constants, that works, but unfortunately, my code has variables in place of the first #. Obviously, I’m doing time conversions (3600 seconds in an hour).

I reported the problem to Lotus and the response was basically the same as mentioned above. It’s a flaw in the system that they’re aware of. SPR# PCOY5ZJBNH.

They gave similar workarounds such as making the #'s floats by adding “.0”, etc.

Thanks for the advice and info folks.

Dave

Subject: RE: Long vs. Integer bug in LotusScript?

Well I’m glad to hear they consider it a flaw! It is pretty silly. They really only need to be deciding if they’re doing floating point math or not. Beyond that it should scale up to a long if needed. :slight_smile:

Subject: RE: Long vs. Integer bug in LotusScript?

The following works just fine…

Dim fie As Integer

Dim foe As Long ’ or Double …

fie = 23

foe = fie * 3600&

In general, the existence of an SPR only means that somebody considers it a bug – not necessarily that Development does.

The SPR refers to a condition that occurs during compile, when the compiler tries to optimize by pre-evaluating expressions involving constants. Type conversions in these evaluations happen using the same rules that govern type conversions in expressions evaluated at runtime, so if you multiply an Integer by an Integer, the result is expected to fit within an Integer. It could be argued that it’s appropriate for the compiler to generate an error if that is not the case, just as it would generate a runtime error if that occurred when multiplying an Integer variable times an Integer constant, as you were trying to do.

Subject: RE: Long vs. Integer bug in LotusScript?

One can argue a lot of things. Nevertheless, when performing the math, the only issue is whether you need to do floating point calculations or not. Once you’ve got your result you can decide what the result was. Of course this only comes up in the first place because LotusScript uses primitives at all. You could argue that is the real issue… :wink: