Re: [fpc-pascal] string vs char

2021-10-15 Thread Ralf Quint via fpc-pascal

On 10/15/2021 3:16 PM, Ched via fpc-pascal wrote:

Well, well, understand.


OTOH, declaring a string of length 1 is sort of futile -- it uses
two bytes where a plain char declaration takes just one byte.


Not so futile as a string can be empty, not a char ! 


Well, if you don't like it being called "futile, just call it "nonsense" 
instead (in 99.99% of all possible use cases)


Ralf



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Writing Pascal Physics and Vectors

2021-10-15 Thread Anthony Walter via fpc-pascal
I often use squares / cubes and such like:

X := X * X * X;

When I am unsure how much steep of a curve I want. I just add / remove X
and run the test to see if the curve looks good. It's just a preference
thing and considering the other processing intensive stuff going on, I am
sure it doesn't make a lick of difference.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Writing Pascal Physics and Vectors

2021-10-15 Thread Anthony Walter via fpc-pascal
>
> I have writen my own fairly extensive game engine and this will be
> integrated into it sometime soon. My thought was it would be more useful to
> create a minimal version first that other people could evaluate and test
> more easily.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Writing Pascal Physics and Vectors

2021-10-15 Thread Ched via fpc-pascal


> Fade := Fade * Fade * Fade * Fade * Fade;

Why not Fade:=sqr(sqr(Fade))*fade ?

Cheers, Anthony, Ched




Le 15.10.21 à 22:18, Anthony Walter via fpc-pascal a écrit :
I've been working on writing Pascal bindings a friendly object orient interface to a few open source 
projects. I have put together Chipmunk2D, NanoVG, MiniMP3, and SDL2 for rendering nice real time platform 
independent programs where fast logic can be easily controlled with physics or fast graphics can easily 
be rendered.


If you are interested in hearing more, I've put up a quick and dirty video of one of my test scene that 
precisely detects points of contact and the forces behind them at the page below.


https://www.getlazarus.org/videos/physics/collisions/ 


Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off 
people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a 
Discord channel.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Writing Pascal Physics and Vectors

2021-10-15 Thread DougC via fpc-pascal
I would be helpful if you could meld this work into other Pascal-based efforts, 
such as the Castle Game Engine. I don't know the details of CGE but if it could 
use more of this type of functionality, why not make your work even more useful 
by connecting up with CGE?



Doug C.






 On Fri, 15 Oct 2021 18:18:13 -0400 Anthony Walter via fpc-pascal 
 wrote 


I've been working on writing Pascal bindings a friendly object orient interface 
to a few open source projects. I have put together Chipmunk2D, NanoVG, MiniMP3, 
and SDL2 for rendering nice real time platform independent programs where fast 
logic can be easily controlled with physics or fast graphics can easily be 
rendered.



If you are interested in hearing more, I've put up a quick and dirty video of 
one of my test scene that precisely detects points of contact and the forces 
behind them at the page below.



https://www.getlazarus.org/videos/physics/collisions/


Source code for the test scene is included on that page. If you want to help, I 
need to bounce ideas off people as well as test on Raspberry Pi, Mac, and 
Windows. Message me and maybe we can try to meet on a Discord channel.


___
fpc-pascal maillist  - mailto:fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Writing Pascal Physics and Vectors

2021-10-15 Thread Anthony Walter via fpc-pascal
I've been working on writing Pascal bindings a friendly object orient
interface to a few open source projects. I have put together Chipmunk2D,
NanoVG, MiniMP3, and SDL2 for rendering nice real time platform independent
programs where fast logic can be easily controlled with physics or fast
graphics can easily be rendered.

If you are interested in hearing more, I've put up a quick and dirty video
of one of my test scene that precisely detects points of contact and the
forces behind them at the page below.

https://www.getlazarus.org/videos/physics/collisions/

Source code for the test scene is included on that page. If you want to
help, I need to bounce ideas off people as well as test on Raspberry Pi,
Mac, and Windows. Message me and maybe we can try to meet on a Discord
channel.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] string vs char

2021-10-15 Thread Ched via fpc-pascal

Well, well, understand.


OTOH, declaring a string of length 1 is sort of futile -- it uses
two bytes where a plain char declaration takes just one byte.


Not so futile as a string can be empty, not a char !

Regards, Dennis, Ched'
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why the difference in the rounded results?

2021-10-15 Thread Guillermo via fpc-pascal
Hi,

Silly question: Were all compiled an executed in the same computer
and operating system?  Also, were all compilations done with same
optimization configuration?

It is well known that different CPUs have differences in some
operations, specially DIV ones that even introduced bugs in the past
(i.e. the infamous Pentium DIV).  Also different compilers may introduce
different configurations about math processing if you didn't set one
(i.e. using the "default" CPU).  Maybe some assume Pentium (so it should
workaround DIV operations) and other don't.

Also if it was compiled in a way that doesn't use the CPU math
operations different operating systems/library versions may have
different implementations for the same operation.

Regards,
Guillermo Martínez.


El Fri, 15 Oct 2021 11:49:59 +0200
Gabor Boros via fpc-pascal  escribió:
> Hi All,
> 
> I got different results with 32bit vs. 64bit, 3.2.2 vs. 3.3.1, FPC
> vs. Delphi. Why?
> 
> var
>d1,d2:Double;
> 
> begin
>d1:=20.5;
>d2:=1.05;
>Writeln(RoundTo(d1*d2,-2));
>Writeln(SimpleRoundTo(d1*d2));
>d1:=28.9;
>Writeln;
>Writeln(RoundTo(d1*d2,-2));
>Writeln(SimpleRoundTo(d1*d2));
>d1:=21.5;
>Writeln;
>Writeln(RoundTo(d1*d2,-2));
>Writeln(SimpleRoundTo(d1*d2));
>Readln;
> end.
> 
> - FPC 3.2.2 Win32
> 
>   2.1531E+001
>   2.1531E+001
> 
>   3.0340E+001
>   3.0340E+001
> 
>   2.2570E+001
>   2.2570E+001
> 
> - FPC 3.2.2 Win64
> 
>   2.1523E+001
>   2.1531E+001
> 
>   3.0347E+001
>   3.0351E+001
> 
>   2.2574E+001
>   2.2578E+001
> 
> - FPC 3.3.1 Win32
> 
>   2.1531E+001
>   2.1531E+001
> 
>   3.0340E+001
>   3.0340E+001
> 
>   2.2570E+001
>   2.2570E+001
> 
> - FPC 3.3.1 Win64
> 
>   2.1523E+001
>   2.1531E+001
> 
>   3.0347E+001
>   3.0351E+001
> 
>   2.2574E+001
>   2.2578E+001
> 
> - Delphi 10.4.2 Win32
> 
>   2.153000E+0001
>   2.153000E+0001
> 
>   3.034000E+0001
>   3.034000E+0001
> 
>   2.258000E+0001
>   2.258000E+0001
> 
> - Delphi 10.4.2 Win64
> 
>   2.152000E+0001
>   2.153000E+0001
> 
>   3.034000E+0001
>   3.035000E+0001
> 
>   2.258000E+0001
>   2.258000E+0001
> 
> Gabor
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Why the difference in the rounded results?

2021-10-15 Thread Ched via fpc-pascal

Hello All,

In https://wiki.freepascal.org/Variables_and_Data_Types about Strings:
 // where:  1 < length <= 255
is to read as
 // where:  1 <= length <= 255
isn't it ?

Cheers, Ched

Le 15.10.21 à 18:44, James Richters via fpc-pascal a écrit :

The difference is because of the way floating point math works.. and how 
rounding works.
Rounding something that ends with 5 is ambiguous, because it could round up, or 
it could round down...
You can control the behavior of rounding with SetRoundMode();
See https://www.freepascal.org/docs-html/rtl/math/setroundmode.html
It seems that SetRoundMode is defaulting to SetRoundMode(rmNearest) which 
doesn't resolve ambiguity for things like 22.57500...  because there is no 
nearest... 22.57 is EXACTLY the same distance away as 22.58... BUT since we are 
using floating point... there could be a tiny difference between one or the 
other making SetRoundMode(rmNearest) round one way for 32 bit and another way 
for 64 bit.
If you want them to always round the same way, you can just set SetRoundMode() 
to either SetRoundMode(rmUp) or SetRoundMode(rmDown) and that will remove the 
ambiguity...
Note that rmUp or rmDown or rmNearest only affect result that round off 
something with a 5
So with rmUP
22.575 will ALWAYS come out 22.58
And with rmDown
22.575 will ALWAYS come out 22.57

The reason Delphi is showing 2.258000E+0001
And FPC 64 bit is showing   2.2578E+001
Is because delphi is not showing all the floating point digits... if you do
Writeln(SimpleRoundTo(d1*d2):0:14); with FPC you get
22.58 because now you are only showing 14 digits after the decimal 
point like Delphi , not 16 digits like FPC

Note that floating point math with double precision, it's impossible to truly 
store the number 22.58,
It's either 22.579 on win 32  or 22.578 on 64bit 
there is no exact 22.58. you have 
to be one float value or the other.  So it doesn't make sense to round a 
floating point number then try to display more decimal points than you rounded 
it to,   if you are rounding to 2 decimal places than just to a writeln that 
shows 2 decimal places likeWriteln(RoundTo(d1*d2,-2):0:2);  and see 22.57 
otherwise you will always be seeing floating point weirdness.

There is a difference between the way 64bit stores 22.575, 22.570 and 22.580
If you do
Writeln(22.575:0:20);
Writeln(22.57:0:20);
Writeln(22.58:0:20);

On a 32bit, you get:
22.57500070
22.5670
22.5790

On 64bit you get:
22.5740
22.5700
22.5780
Yes, it's true, Win32 has more precision than Win64  I did not get them 
backwards.. see:
https://wiki.freepascal.org/Variables_and_Data_Types

Where it states:
Note that for Windows 64 bits and non-Intel targets Extended is an alias for 
Double.  So I don't use Win64,  I only use 32 bit so I can get the precision.

So when using SetRoundMode(rmNearest) which is the default to decide whether to 
round 22.575 up or down it's very slightly in nearest to 22.58 with 64 bit and 
very slightly nearest to 22.57 with 32 bit

James

-Original Message-
From: fpc-pascal  On Behalf Of Gabor 
Boros via fpc-pascal
Sent: Friday, October 15, 2021 5:50 AM
To: fpc-pascal@lists.freepascal.org
Cc: Gabor Boros 
Subject: [fpc-pascal] Why the difference in the rounded results?

Hi All,

I got different results with 32bit vs. 64bit, 3.2.2 vs. 3.3.1, FPC vs.
Delphi. Why?

var
d1,d2:Double;

begin
d1:=20.5;
d2:=1.05;
Writeln(RoundTo(d1*d2,-2));
Writeln(SimpleRoundTo(d1*d2));
d1:=28.9;
Writeln;
Writeln(RoundTo(d1*d2,-2));
Writeln(SimpleRoundTo(d1*d2));
d1:=21.5;
Writeln;
Writeln(RoundTo(d1*d2,-2));
Writeln(SimpleRoundTo(d1*d2));
Readln;
end.

- FPC 3.2.2 Win32

   2.1531E+001
   2.1531E+001

   3.0340E+001
   3.0340E+001

   2.2570E+001
   2.2570E+001

- FPC 3.2.2 Win64

   2.1523E+001
   2.1531E+001

   3.0347E+001
   3.0351E+001

   2.2574E+001
   2.2578E+001

- FPC 3.3.1 Win32

   2.1531E+001
   2.1531E+001

   3.0340E+001
   3.0340E+001

   2.2570E+001
   2.2570E+001

- FPC 3.3.1 Win64

   2.1523E+001
   2.1531E+001

   3.0347E+001
   3.0351E+001

   2.2574E+001
   2.2578E+001

- Delphi 10.4.2 Win32

   2.153000E+0001
   2.153000E+0001

   3.034000E+0001
   3.034000E+0001

   2.258000E+0001
   2.258000E+0001

- Delphi 10.4.2 Win64

   2.152000E+0001
   2.153000E+0001

   3.034000E+0001
   3.035000E+0001

   2.258000E+0001
   2.258000E+0001

Gabor

Re: [fpc-pascal] Why the difference in the rounded results?

2021-10-15 Thread James Richters via fpc-pascal
The difference is because of the way floating point math works.. and how 
rounding works.
Rounding something that ends with 5 is ambiguous, because it could round up, or 
it could round down... 
You can control the behavior of rounding with SetRoundMode();
See https://www.freepascal.org/docs-html/rtl/math/setroundmode.html
It seems that SetRoundMode is defaulting to SetRoundMode(rmNearest) which 
doesn't resolve ambiguity for things like 22.57500...  because there is no 
nearest... 22.57 is EXACTLY the same distance away as 22.58... BUT since we are 
using floating point... there could be a tiny difference between one or the 
other making SetRoundMode(rmNearest) round one way for 32 bit and another way 
for 64 bit. 
If you want them to always round the same way, you can just set SetRoundMode() 
to either SetRoundMode(rmUp) or SetRoundMode(rmDown) and that will remove the 
ambiguity... 
Note that rmUp or rmDown or rmNearest only affect result that round off 
something with a 5 
So with rmUP 
22.575 will ALWAYS come out 22.58 
And with rmDown 
22.575 will ALWAYS come out 22.57

The reason Delphi is showing 2.258000E+0001
And FPC 64 bit is showing   2.2578E+001
Is because delphi is not showing all the floating point digits... if you do
Writeln(SimpleRoundTo(d1*d2):0:14); with FPC you get
22.58 because now you are only showing 14 digits after the decimal 
point like Delphi , not 16 digits like FPC

Note that floating point math with double precision, it's impossible to truly 
store the number 22.58, 
It's either 22.579 on win 32  or 22.578 on 64bit 
there is no exact 22.58. you have 
to be one float value or the other.  So it doesn't make sense to round a 
floating point number then try to display more decimal points than you rounded 
it to,   if you are rounding to 2 decimal places than just to a writeln that 
shows 2 decimal places likeWriteln(RoundTo(d1*d2,-2):0:2);  and see 22.57 
otherwise you will always be seeing floating point weirdness.

There is a difference between the way 64bit stores 22.575, 22.570 and 22.580
If you do 
   Writeln(22.575:0:20);
   Writeln(22.57:0:20);
   Writeln(22.58:0:20);

On a 32bit, you get:
22.57500070
22.5670
22.5790

On 64bit you get:
22.5740
22.5700
22.5780
Yes, it's true, Win32 has more precision than Win64  I did not get them 
backwards.. see:
https://wiki.freepascal.org/Variables_and_Data_Types

Where it states:
Note that for Windows 64 bits and non-Intel targets Extended is an alias for 
Double.  So I don't use Win64,  I only use 32 bit so I can get the precision.

So when using SetRoundMode(rmNearest) which is the default to decide whether to 
round 22.575 up or down it's very slightly in nearest to 22.58 with 64 bit and 
very slightly nearest to 22.57 with 32 bit

James

-Original Message-
From: fpc-pascal  On Behalf Of Gabor 
Boros via fpc-pascal
Sent: Friday, October 15, 2021 5:50 AM
To: fpc-pascal@lists.freepascal.org
Cc: Gabor Boros 
Subject: [fpc-pascal] Why the difference in the rounded results?

Hi All,

I got different results with 32bit vs. 64bit, 3.2.2 vs. 3.3.1, FPC vs. 
Delphi. Why?

var
   d1,d2:Double;

begin
   d1:=20.5;
   d2:=1.05;
   Writeln(RoundTo(d1*d2,-2));
   Writeln(SimpleRoundTo(d1*d2));
   d1:=28.9;
   Writeln;
   Writeln(RoundTo(d1*d2,-2));
   Writeln(SimpleRoundTo(d1*d2));
   d1:=21.5;
   Writeln;
   Writeln(RoundTo(d1*d2,-2));
   Writeln(SimpleRoundTo(d1*d2));
   Readln;
end.

- FPC 3.2.2 Win32

  2.1531E+001
  2.1531E+001

  3.0340E+001
  3.0340E+001

  2.2570E+001
  2.2570E+001

- FPC 3.2.2 Win64

  2.1523E+001
  2.1531E+001

  3.0347E+001
  3.0351E+001

  2.2574E+001
  2.2578E+001

- FPC 3.3.1 Win32

  2.1531E+001
  2.1531E+001

  3.0340E+001
  3.0340E+001

  2.2570E+001
  2.2570E+001

- FPC 3.3.1 Win64

  2.1523E+001
  2.1531E+001

  3.0347E+001
  3.0351E+001

  2.2574E+001
  2.2578E+001

- Delphi 10.4.2 Win32

  2.153000E+0001
  2.153000E+0001

  3.034000E+0001
  3.034000E+0001

  2.258000E+0001
  2.258000E+0001

- Delphi 10.4.2 Win64

  2.152000E+0001
  2.153000E+0001

  3.034000E+0001
  3.035000E+0001

  2.258000E+0001
  2.258000E+0001

Gabor
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org

[fpc-pascal] Why the difference in the rounded results?

2021-10-15 Thread Gabor Boros via fpc-pascal

Hi All,

I got different results with 32bit vs. 64bit, 3.2.2 vs. 3.3.1, FPC vs. 
Delphi. Why?


var
  d1,d2:Double;

begin
  d1:=20.5;
  d2:=1.05;
  Writeln(RoundTo(d1*d2,-2));
  Writeln(SimpleRoundTo(d1*d2));
  d1:=28.9;
  Writeln;
  Writeln(RoundTo(d1*d2,-2));
  Writeln(SimpleRoundTo(d1*d2));
  d1:=21.5;
  Writeln;
  Writeln(RoundTo(d1*d2,-2));
  Writeln(SimpleRoundTo(d1*d2));
  Readln;
end.

- FPC 3.2.2 Win32

 2.1531E+001
 2.1531E+001

 3.0340E+001
 3.0340E+001

 2.2570E+001
 2.2570E+001

- FPC 3.2.2 Win64

 2.1523E+001
 2.1531E+001

 3.0347E+001
 3.0351E+001

 2.2574E+001
 2.2578E+001

- FPC 3.3.1 Win32

 2.1531E+001
 2.1531E+001

 3.0340E+001
 3.0340E+001

 2.2570E+001
 2.2570E+001

- FPC 3.3.1 Win64

 2.1523E+001
 2.1531E+001

 3.0347E+001
 3.0351E+001

 2.2574E+001
 2.2578E+001

- Delphi 10.4.2 Win32

 2.153000E+0001
 2.153000E+0001

 3.034000E+0001
 3.034000E+0001

 2.258000E+0001
 2.258000E+0001

- Delphi 10.4.2 Win64

 2.152000E+0001
 2.153000E+0001

 3.034000E+0001
 3.035000E+0001

 2.258000E+0001
 2.258000E+0001

Gabor
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal