Recent

Author Topic: Lazarus appear to wrong arithmetic operations with big nums.  (Read 5306 times)

Tommi

  • Sr. Member
  • ****
  • Posts: 256
Lazarus appear to wrong arithmetic operations with big nums.
« on: November 19, 2007, 09:50:05 pm »
This simple code returns 148321786 and not 87956783576570.
I need it for crc64 operations.

Some idea ?

Thank You

procedure TForm1.Button2Click(Sender: TObject);
var
CRC64:TCRC64;
P:pointer;
a,b:integer;
x:int64;
begin
a:=8795678357657;b:=0;
edit1.Text:=inttostr(a*10);
end;

cyber_python

  • Jr. Member
  • **
  • Posts: 79
RE: Lazarus appear to wrong arithmetic operations with big n
« Reply #1 on: November 19, 2007, 10:25:34 pm »
An integer can go up to 2,147,483,647 .
Use int64 instead of integer, which can go up to 9,223,372,036,854,775,807.
Hope this helps.

Tommi

  • Sr. Member
  • ****
  • Posts: 256
Lazarus appear to wrong arithmetic operations with big nums.
« Reply #2 on: November 20, 2007, 08:59:03 am »
I tried but it's the same.

In anycase Integer is also int64. (http://www.freepascal.org/docs-html/ref/refsu5.html#x25-240003.1.1)

Temporarily I solved so:


for cc := 1 to 256 do x:=x+a;     //the same as x:=a*256;

It works, but is very bad

arnoldb

  • Jr. Member
  • **
  • Posts: 97
Lazarus appear to wrong arithmetic operations with big nums.
« Reply #3 on: November 20, 2007, 11:52:48 am »
It depends on the CPU target...

If you are compiling for I386 (default), integer is only 2 bytes and not the same as int64.

If you set your cpu target to Pentium Pro/ Pentium 2 in menu Project->Compiler Options->Code->Target i386, then FPC compiles for a 4-byte integer, which is the same as int64.

Hope this helps

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2674
Lazarus appear to wrong arithmetic operations with big nums.
« Reply #4 on: November 20, 2007, 12:09:46 pm »
in default mode (when no mode is specified) and interg is 16 bit (2 bytes)

In $mode objfpc (which all lazarus units are, see top of file) or in $mode delphi an integer is 32bit (4 bytes) indipendent of the CPU used

an int64 is allways 64 bit (8 bytes).
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Tommi

  • Sr. Member
  • ****
  • Posts: 256
Lazarus appear to wrong arithmetic operations with big nums.
« Reply #5 on: November 22, 2007, 08:19:33 pm »
Thank You, Issue is solved.

 

TinyPortal © 2005-2018