which integer variable type can hold 1442907270

Started by Zlatko Vid, October 02, 2026, 09:42:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

ordinary variable like
v can hold such large integer number

but
when i use it in array like

arr[1] = 1442907270

then i get wrong result
seems that is limited to 8 digits ?
do i have right ?
or
do i must use trick to fool it like
string then convert it to large number ?
thanks
  •  

Zlatko Vid

OR
i lost last two digits in wrong transformation
sorry yes i made mistake and
return it as FLOAT TYPE

but interesting if number is with 8 digit
it is returned properly
how is that ?

Charles is this somehow connected with NumberFormat statements
currently i use
NumberFormat 6,1,0,0,0,0
thanks

  •  

Charles Pegge

#2
 
Hi Aurel,

Normally, I never touch these settings.
The defaults are 16,1,0,0,0,0
type numformat
    int dp   ' DECIMAL PLACES
    int trz  ' STRIP TRAILING ZEROS
    int sn   ' SCIENTIFIC NOTATION BY DEFAULT
    int sdp  ' INHIBIT ZERO BEFORE DECIMAL POINT
    int sns  ' LEADING SPACE FOR NON NEGATIVE NUMBERS
    int lps  ' LEAD PADDING SPACES
  end type

If you want to limit the decimal places displayed then:
print str(x,5)  'limits the number string decimal places to 5 instead of 16



for 32bit integers, you can check the max values:

dword a
a=0xffffffff
print a cr hex a 'about 4.2 gig

int a
a=0x7fffffff 'about 2.1 gig
print a cr hex a



Zlatko Vid

Hi Charles
I don't have problem with decimal places
than with internal conversion

FLOAT to INT
which reduced two last digit or give wrong result

like this:
'test large integer as array element
int arr[10]
float v
arr[1] = 1442907270

'test
print str(arr[1])

v = arr[1]

print str(v)

with smaller number there is no problem only whit larger
i used for image hdc
  •  

Charles Pegge

You lose precision when converting from a large 32bit integer to a (32bit) float. The problem is solved by using a double (64bit).

A 32bit float only has a 23 bits mantissa (precision), 8 bits of exponent and 1 bit for the sign.


Zlatko Vid

Yes Charles
you have right as usual  ;)

same code with double

'test large integer as array element
int arr[10]
double v
arr[1] = 1442907270

'test
print str(arr[1])

v = arr[1]

print str(v)
  •