April 28, 2024, 09:51:25 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


BUG? Int64 has a 32 bit numeric range?

Started by Kale, August 12, 2006, 10:53:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kale


global sub main()
{
int64 Test = 2147483648;
print(str$(Test));

While (GetKey() = "")
{

}
}


Why does this number wrap? I thought that a signed Int64 could handle a positive number up to: 9223372036854775807

Ionic Wind Support Team

Read the tutorials.  See 'type modifiers'.

int64 Test = 2147483648q;

The 'q' tells the lexer to treat the number as an int64 and not an int.
Ionic Wind Support Team

Kale

Thats odd but i guess it makes sense.

Is this particular to Aurora or does this work like this in C++?

Ionic Wind Support Team

Type modifiers are common in all compilers.

Compilers (lexers) work by scanning the input file and returning tokens.  However there is only so much a lexer can guess at.  When a numeric sequence is seen there is two ways to convert from ascii to integer.  One returns a 32 bit value and the other a 64 bit value. Since the most common usage will be 32 bits a numeric constant will be scanned as a signed integer value unless overrided.  The type modifiers support by Aurora, and listed in the tutorial are:

f = float
q = quad
u = unsigned (for hex constants).

The default for numeric constants in Aurora are double and int.  Which is the same in C too. You can force the compiler to treate all numerics with a decimal point as a float constant with the preprocessor command

#assume "float"

When your oprimizing your own code it's important to keep these in mind.  For example:

float f;
f = 1.2345;

The lexer sees the numeric constant as a double precision number.  The compiler adds assembly code to load the double value into the math coprocessor and convert it to a 32 bit single precision number. Which is all automatic of course, but adds quite a number of instructions.

float f;
f = 1.2345f;

The variable is a 32 bit single precision number and so is the numeric constant.  So the compiler can perform the assignment with a single MOV instruction.  The same applies the other way around.

double d;
d = 1.2345f;

Again a conversion has to take place resulting in more assembly instrucitons. 

Some languages only have one integer and one floating point type so you never have to worry about type conversions.  But we have the flexibility of using any type.

Paul.

Ionic Wind Support Team

Kale

Very helpful reply thanks, I come from a Python and PureBasic background so this is something i will need to remember. thanks again. :)