Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-03

Re: Bug or not Bug

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vincent Snijders
Show quoted text 34 lines
* Hi Fpc-list, I'm having trouble using Round: ----- [ BOF: test.pas ] ----- Program Test ; Uses Math, SysUtils ; Var i : Byte ; Begin For i := 0 to 31 do WriteLn(Format('%d %.8x',[i,Round(Ldexp(1,i))])) ; End. ----- [ EOF: test.pas ] ----- ,----- [ FPC: ] | 0 00000001 | [...] | 30 40000000 | An unhandled exception occurred at 0x004109D1 : | EINVALIDOP : Invalid floating point operation | 0x004109D1 | 0x0006FF78 | 0x8D000CC2 `----- ,----- [ Delphi: ] | 0 00000001 | [...] | 30 40000000 | 31 80000000 `----- Any idea ?

Round returns a longint. The range of a longint is -2^31 .. (2^31-1). The result you had (2^31) doesn't fit in a longint, so this is not a fpc bug.

As I don't have Delphi, I don't know why Delphi doesn't give an error. It could be that the Delphi's return value is int64 or cardinal. Or it simply doesn't care about the overflow. What happens in delphi if the formatstring is '%d %d'?

HTH,
Vincent.

Reply by email

Peter Vreman
to Vincent Snijders
Show quoted text 10 lines
Round returns a longint. The range of a longint is -2^31 .. (2^31-1). The result you had (2^31) doesn't fit in a longint, so this is not a fpc bug. As I don't have Delphi, I don't know why Delphi doesn't give an error. It could be that the Delphi's return value is int64 or cardinal. Or it simply doesn't care about the overflow. What happens in delphi if the formatstring is '%d %d'?

FPC 1.9.x has round() that supports int64.

Reply by email

Thomas Schatzl
to Vincent Snijders: On Thu, 11 Mar 2004 12:32:24 +0200 Round returns a longint. The range of a longint is…

Hello,

Show quoted text 21 lines
> I'm having trouble using Round: > ----- [ BOF: test.pas ] ----- > Program Test ; > Uses > Math, SysUtils ; > > Var > i : Byte ; > Begin > For i := 0 to 31 do > WriteLn(Format('%d %.8x',[i,Round(Ldexp(1,i))])) ; > End. > ----- [ EOF: test.pas ] ----- > > ... snip ... > > Any idea ? Round returns a longint. The range of a longint is -2^31 .. (2^31-1). The result you had (2^31) doesn't fit in a longint, so this is not a fpc

bug.

As I don't have Delphi, I don't know why Delphi doesn't give an error. It

could

be that the Delphi's return value is int64 or cardinal. Or it simply

doesn't

Delphi's round() returns an int64.

care about the overflow. What happens in delphi if the formatstring is '%d

%d'?

%d just indicates that the given value is an integer - the format function itself does not limit the number of digits (or the range of the given value) in this case.

Regards,
Thomas

Reply by email

Peter Vreman
Show quoted text 12 lines
| An unhandled exception occurred at 0x00407A0B : | EAccessViolation : Access violation | 0x00407A0B | 0x00405948 | 0x00065974 | 0x000000C3 | An unhandled exception occurred at 0x00407A0B : [...] | EAccessViolation : Access violation | ^C `----------------------- Any idea ?

Compile with debug info and run it in gdb.

Reply by email