Why can't Constants IN IDE be set to specific numeric type?

When you define a constant in the IDE you can only assign it’s type as Number and not the specific numeric type. This has bothered me for a long time, but as it usually does not matter I have not said anything about it, but there are are times it can.

I thought maybe the IDE was smart enough to detect what numeric type to use… and finally decided to test that…

So I created a Constant called UInt64Max and set the value to 18446744073709551615…

And then did this:
Dim IU64 as Uint64 =Uint64Max\2

And guess what … the value of IU64 was 0!!!

The reason is easy to understand. I exported the module I put that in as text and here is what I saw:

#tag Module Protected Module Module1 #tag Constant, Name = Uint64Max, Type = Double, Dynamic = False, Default = \"18446744073709551615", Scope = Public #tag EndConstant End Module #tag EndModule

So all the numeric constants are stored as doubles… not only can that produce wrong results but even when it does not, it can also introduce extra numeric type conversion overhead in our code making it less efficient.

I go back to before UInt64 was added to the language and back then a double could hold all numeric types without losing information (though the conversion overhead issue was still there)…

But when the additional datatypes were added this was missed…
The thing is this type of stuff SHOULD be rock solid… While i don’t use it, I think I’ve heard that Currency still is not rock solid…

The need for API 2.0 was sold as a need to deal with all the changes/additions to the language/framework over the years and rationalize them and make them consistent… And that IS a need… one that at the most basic level API 2 mostly does not deal with IMO.

  • karen

I would definitely FR that, Karen. I use constants pretty liberally for pre-calculated values to speed up intensive operations. I’ve not run in to this, and that’s surprising.

Thanks for checking this, tracking down the issue, and reporting it here!

I reported it as a bug, which I think it is!!!


quite literally because the IDE doesnt support allowing you to enter a type :slight_smile:

the compiler supports it - the IDE doesnt

theres a few thing constants defined in the IDE cant do that ones defined in code can

[quote=461736:@Norman Palardy]quite literally because the IDE doesnt support allowing you to enter a type :slight_smile:

Seems like that should be a relatively easy thing to fix!


heh … famous last words :slight_smile: