Re: [fpc-pascal] Installing FPC on CentOS 5 x64

2007-10-28 Thread Coco Pascal

Paulo Estrela schreef:

Hi,

I was trying to install fpc 2.2.0 on a CentOS 5 x64 machine using rpm
package, but libtinfo.so.5 is required. My system doesn`t have this
lib and I didn`t find anything on Internet related to this. Anyone
with same problem or any idea?
  
I'm running FPC 2.2.0 on CentOS 5 x86_64. I use the Lazarus snapshot 
build which apparently doesn't require libtinfo.so.5

You can download it here: http://www.hu.freepascal.org/lazarus/
You can debug your code only when source files are in the project 
directory. See: http://www.freepascal.org/mantis/view.php?id=9899

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Milan Marusinec

Hello folks,

This one looks pretty elementary, but to my big surprise
it doesn't work as I would expect.

I'd like to ask FreePascal compiler creators, how can I safely
evaluate double variables in case like this.

Sample program with comment is in attachement ...

Milano

//
// Hm. This is really weird. I assign 1 to x, which is of double type.
// Then I add 0.4 to the x, then I subtract 0.4 from x.
// So, now I should have 1 in x. But when I compare x with 1, I get
// wrong evaluation of "if x = 1 then" statement !
//
// I tried this on two different Windows Intel machines and it was wrong.
// I tried it also on Mac with PowerPC processor and it was also wrong.
// (Both Delphi & FPC compilers)
//
// [EMAIL PROTECTED]
//
program
 floating_error_1_4 ;

{$APPTYPE CONSOLE }

var
 x : double;

BEGIN
 x:=1;
 x:=x + 0.4;
 x:=x - 0.4;

 if x = 1.0 then
  writeln('OK: x = 1 ' )
 else
  writeln('Error: "if x = 1" is evaluated wrong  ' );

END.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Daniël Mantione


Op Sun, 28 Oct 2007, schreef Milan Marusinec:

> Hello folks,
> 
> This one looks pretty elementary, but to my big surprise
> it doesn't work as I would expect.
> 
> I'd like to ask FreePascal compiler creators, how can I safely
> evaluate double variables in case like this.
> 
> Sample program with comment is in attachement ...

If you do on a hand calculator:

1/3

... you will see:

0.333

If you multiply again with 3, you will see:

0.999

... and not 1.000.

There is a similar issue here. The value "0.4" cannot be stored exactly in 
a computer, therefore it is rounded.

This behaviour normal and while annoying, it is simply how things work 
in the digital world, you will have to work around it.

Daniël___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Joao Morais

Daniël Mantione wrote:
There is a similar issue here. The value "0.4" cannot be stored exactly in 
a computer, therefore it is rounded.


This behaviour normal and while annoying, it is simply how things work 
in the digital world, you will have to work around it.


Or, of course, use a scaled integer type like Currency.

--
Joao Morais

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Daniël Mantione


Op Sun, 28 Oct 2007, schreef Joao Morais:

> Daniël Mantione wrote:
> > There is a similar issue here. The value "0.4" cannot be stored exactly
> > in a computer, therefore it is rounded.
> > 
> > This behaviour normal and while annoying, it is simply how things work in
> > the digital world, you will have to work around it.
> 
> Or, of course, use a scaled integer type like Currency.

This is indeed a question you should ask, but you should generalize it. In 
mathematics we consider several groups of numbers:

N - Natural numbers
Z - Integer numbers
Q - Rational numbers
R - Real numbers
C - Complex numbers

Subranges of N, Z and Q can be represented exactly in a computer. R and C 
can not, we use the floating point system as approximation. Very often, a 
certain calculation that on the first sight might tempt one to use a real, 
can be performed in N or Q. In such case floating point is overkill and 
thus, you can save yourself a lot of trouble by calculating it in N or Q.

Daniël___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread L
> > If you do on a hand calculator:
> > 
> > 1/3
> > 
> > ... you will see:
> > 
> > 0.333
> > 
> > If you multiply again with 3, you will see:
> > 
> > 0.999
> > 
> > ... and not 1.000.


On my electronic/digital calculator I see '1'

It is a casio fx-300SA

Maybe $5 digital calculators are smarter than $3000 computers ;)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Florian Klaempfl
L schrieb:
>>> If you do on a hand calculator:
>>>
>>> 1/3
>>>
>>> ... you will see:
>>>
>>> 0.333
>>>
>>> If you multiply again with 3, you will see:
>>>
>>> 0.999
>>>
>>> ... and not 1.000.
> 
> 
> On my electronic/digital calculator I see '1'

They calculate usually internally with more digits than they display or
they even might use bcd numbers which makes the program working with fpc
as well:

//
// Hm. This is really weird. I assign 1 to x, which is of double type.
// Then I add 0.4 to the x, then I subtract 0.4 from x.
// So, now I should have 1 in x. But when I compare x with 1, I get
// wrong evaluation of "if x = 1 then" statement !
//
// I tried this on two different Windows Intel machines and it was wrong.
// I tried it also on Mac with PowerPC processor and it was also wrong.
// (Both Delphi & FPC compilers)
//
// [EMAIL PROTECTED]
//
program
 floating_error_1_4 ;

 uses
   fmtbcd;

{$APPTYPE CONSOLE }

var
 x : TBCD;

BEGIN
 x:=1;
 x:=x + 0.4;
 x:=x - 0.4;

 if x = 1.0 then
  writeln('OK: x = 1 ' )
 else
  writeln('Error: "if x = 1" is evaluated wrong  ' );

END.

> 
> It is a casio fx-300SA
> 
> Maybe $5 digital calculators are smarter than $3000 computers ;)
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Daniël Mantione


Op Sun, 28 Oct 2007, schreef L:

> > > If you do on a hand calculator:
> > > 
> > > 1/3
> > > 
> > > ... you will see:
> > > 
> > > 0.333
> > > 
> > > If you multiply again with 3, you will see:
> > > 
> > > 0.999
> > > 
> > > ... and not 1.000.
> 
> 
> On my electronic/digital calculator I see '1'
> 
> It is a casio fx-300SA
> 
> Maybe $5 digital calculators are smarter than $3000 computers ;)

It isn't smarter, but it has more digits. Press the "pi" button and 
subtract the number you see in your display. That'll reveal how many 
digits your calculation uses.

Regarding the $3000 computer: An extended has 20 digits of precision. 
Make sure you round your output to 10 digits and you need to a very weird 
calcation until you can see a rounding difference :) 

Daniël___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread L
> Regarding the $3000 computer: An extended has 20 digits of precision. 
> Make sure you round your output to 10 digits and you need to a very weird 
> calcation until you can see a rounding difference :) 

I was talking about $3000 pascal dollars:

BEGIN
  writeln($3000);
END.

Output:
12288

The Pascal dollar is worth a lot more than you think.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Marco van de Voort
> > Regarding the $3000 computer: An extended has 20 digits of precision. 
> > Make sure you round your output to 10 digits and you need to a very weird 
> > calcation until you can see a rounding difference :) 
> 
> I was talking about $3000 pascal dollars:
> 
> BEGIN
>   writeln($3000);
> END.
> 
> Output:
> 12288
> 
> The Pascal dollar is worth a lot more than you think.

It shows the current weak state of the dollar.  Look what 3 and an half euro
is worth nowadays:

  writeln(3E5:10:3);

:-)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Adriaan van Os

Daniël Mantione wrote:


N - Natural numbers
Z - Integer numbers
Q - Rational numbers
R - Real numbers
C - Complex numbers

Subranges of N, Z and Q can be represented exactly in a computer.


> R and C

can not, we use the floating point system as approximation.


This is big nonsense. The issue is not if they can be "represented in a computer" but that a 
10-base decimal fraction can not be represented exactly in a 2-base floating point format.


Regards,

Adriaan

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why this evaluates on "if" wrong ?

2007-10-28 Thread Daniël Mantione


Op Sun, 28 Oct 2007, schreef Adriaan van Os:

> Daniël Mantione wrote:
> 
> > N - Natural numbers
> > Z - Integer numbers
> > Q - Rational numbers
> > R - Real numbers
> > C - Complex numbers
> > 
> > Subranges of N, Z and Q can be represented exactly in a computer.
> 
> > R and C
> > can not, we use the floating point system as approximation.
> 
> This is big nonsense.

Why? There exists no data structure that can hold any number from R or C.

> The issue is not if they can be "represented in a
> computer" but that a 10-base decimal fraction can not be represented exactly
> in a 2-base floating point format.

Indeed, and this is because the 2-base floating format is an approximation 
of R, while the datatype name "real" gives the impression that the 
datatype can hold the real numbers.

Daniël___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Re: Why this evaluates on "if" wrong ?

2007-10-28 Thread Milan Marusinec


This behaviour normal and while annoying, it is simply how things work 
in the digital world, you will have to work around it.


Daniël

oh yes, this is one of the possible workarounds:

function is_equal_dbl(a ,b : double ) : boolean;
const
epsilon = 1e-14;

begin
result:=Abs(a - b ) < epsilon;

end;

It's just one more funny thing one must realize,
when comparing real numbers with some exact
real constants. After this, I will try to never
compare doubles directly, but using tricks like
above. Because, in this digital world
1 + 0.4 - 0.4 <> 1.

Milano

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Compiling / Make problems, latest SVN

2007-10-28 Thread Tobias Giesen
Hello,

I am trying to compile the latest FPC 2.3 SVN on OS X i386 with 
CPU_TARGET=powerpc.

The crosscompiling guide on the freepascal web site says to do a:
make cycle

But cycle seems to be no longer there, so I tried compiler_cycle and
also make all.

Make all and make install both produce this error compiling 
pkgwget.pp:

Fatal: Can't find unit process used by pkgglobals

How can I fix this?

Thanks.

Tobias Giesen


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal