Re: [fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread Sven Barth via fpc-pascal
Am 22.08.2017 00:02 schrieb "James Richters" :

The others already wrote about floating point precision, so I won't repeat
that.

> The reason I noticed this is because I have some conditional statements
like
> If Draw_GX_Min<>99.999 then
> Something

*DON'T* compare floating point numbers like that. Instead use SameValue()
from the Math unit which has an additional epsilon value (with a default
value) that defines a lower and upper bound from your desired value to
compare to.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] H2pas tool vs others, C header translation

2017-08-21 Thread Dmitry Boyarintsev
On Sun, Aug 20, 2017 at 5:37 PM,  wrote:

>
> Is there a competing tool that does more, or is updated more?
>

How about this list?
http://wiki.freepascal.org/C_to_Pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] H2pas tool vs others, C header translation

2017-08-21 Thread Dmitry Boyarintsev
On Sun, Aug 20, 2017 at 5:37 PM,  wrote:

> Is h2pas for example the one that is used for Mysql header translations
> and other major C headers?
>

I'm using Chelper.  (http://wiki.freepascal.org/Chelper)
It's my choice, because it preserves comments (which is usually an
important part of open-source libs)
plus, can be configured to handle library header-specific defines.
Naturally, the process is semi-automatic, but get be done quite quickly.


> I am looking to convert the GNU MPFR library header files, or hire someone
> on a bounty to do it if header translation is not so easy with h2pas and
> requires lots of hand work, and close checking.
>

Speaking of bounties.
There was a bounty (http://wiki.freepascal.org/Bounties#Linux_bounties) for
converting libwebsockets to fpc.
I took it and did the conversion using Chelper.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread Daniel Franzini
Long story short: not every single real number have an *exact*
representation in the computer. You have to live with that and learn the
limitations and pitfalls of floating point calculations.

On Mon, Aug 21, 2017 at 7:42 PM, Ralf Quint  wrote:

> On 8/21/2017 3:34 PM, Daniel Franzini wrote:
> > It might be the case (I didn't do the math) that 999.999 doesn't have
> > an exact representation in IEEE-754 double-precision format, so the
> > best you get is an aproximation (a pretty good one, btw).
> Just use WriteLn (Draw_GX_Min:3:16) and you get no mystery digits
> anymore...
>
> In pretty much any programming language/compiler, if you print more
> digits than the precision of the used variable defines, you will get
> random numbers after the defined precision.
> This is not something FreePascal specific, any C/C++ compiler for
> example will do the same thing. People need to learn what limitations
> come along with floating point variables/calculations...
>
> 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
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>



-- 
Daniel

"Let us change our traditional attitude to the construction of programs.
Instead of imagining that our main task is to instruct a computer what to
do, let us concentrate rather on explaining to human beings what we want a
computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other." (
http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And while
I'm not good at painting, drawing, or music, I can write software."
(Yukihiro Matsumoto, a.k.a. ``Matz'')
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread Ralf Quint
On 8/21/2017 3:34 PM, Daniel Franzini wrote:
> It might be the case (I didn't do the math) that 999.999 doesn't have
> an exact representation in IEEE-754 double-precision format, so the
> best you get is an aproximation (a pretty good one, btw).
Just use WriteLn (Draw_GX_Min:3:16) and you get no mystery digits anymore...

In pretty much any programming language/compiler, if you print more
digits than the precision of the used variable defines, you will get
random numbers after the defined precision.
This is not something FreePascal specific, any C/C++ compiler for
example will do the same thing. People need to learn what limitations
come along with floating point variables/calculations...

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
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread Daniel Franzini
It might be the case (I didn't do the math) that 999.999 doesn't have an
exact representation in IEEE-754 double-precision format, so the best you
get is an aproximation (a pretty good one, btw).

On Mon, Aug 21, 2017 at 7:10 PM, Ralf Quint  wrote:

> On 8/21/2017 3:02 PM, James Richters wrote:
> > I am having an issue with a simple floating point application.  I am
> setting a variable to a specific value and immediately after I set it,  it
> is not exactly what I set it to.  Here's an example
> >
> >Draw_GX_Min:=999.999;
> >Writeln(Draw_GX_Min:3:30);
> >
> > The writeln results in 999.999002
> >
> > Why is it not  999.999000  where did
> 0.02 come from?
> >
> Out of thin air... Well, kind of. Double floating point means 16 digits
> of precision, so when you force a 30 digit precision output, anything
> past 16 digits is random garbage, at best...
>
> 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
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>



-- 
Daniel

"Let us change our traditional attitude to the construction of programs.
Instead of imagining that our main task is to instruct a computer what to
do, let us concentrate rather on explaining to human beings what we want a
computer to do." (Donald Knuth)

"Yes, technogeeks can be funny, even if only to each other." (
http://www.boogieonline.com/revolution/science/humor/)"

"Man is driven to create; I know I really love to create things. And while
I'm not good at painting, drawing, or music, I can write software."
(Yukihiro Matsumoto, a.k.a. ``Matz'')
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread Ralf Quint
On 8/21/2017 3:02 PM, James Richters wrote:
> I am having an issue with a simple floating point application.  I am setting 
> a variable to a specific value and immediately after I set it,  it is not 
> exactly what I set it to.  Here's an example
>
>Draw_GX_Min:=999.999;
>Writeln(Draw_GX_Min:3:30);
>
> The writeln results in 999.999002  
>
> Why is it not  999.999000  where did 0.02 
> come from?
>
Out of thin air... Well, kind of. Double floating point means 16 digits
of precision, so when you force a 30 digit precision output, anything
past 16 digits is random garbage, at best...

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
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Freepascal Floating Point Issue

2017-08-21 Thread James Richters
I am having an issue with a simple floating point application.  I am setting a 
variable to a specific value and immediately after I set it,  it is not exactly 
what I set it to.  Here's an example

   Draw_GX_Min:=999.999;
   Writeln(Draw_GX_Min:3:30);

The writeln results in 999.999002  

Why is it not  999.999000  where did 0.02 
come from?

Draw_GX_Min is defined as a Double.  I don't need that much precision for any 
reason.   I'm just trying to understand why it's not what I set it to.

The reason I noticed this is because I have some conditional statements like
If Draw_GX_Min<>99.999 then
Something 

And sometimes they works as expected, and sometimes not.
I realize I could do:

If round(Draw_GX_Min*1000)<>99 then
   Something 

and it would work, but why do I need to do this when I explicitly set it to 
999.999?

Does anyone know what is going on here that would be kind enough to explain it 
to me?

I suspect this has something to do with floating point, but I don't really 
understand what's happening.

Is there a better way to define my variable, perhaps defined as fixed decimal 
point instead of allowing it to float  so that say all numbers from 
-999.9 to 999.9 are guaranteed to be represented accurately to 5 
decimal places so that if I set one to 999.9 it would actually be 999.9 
exactly?  I would rather have less precision but have variables retain exactly 
what they are set to, not something close

Thanks

James




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

Re: [fpc-pascal] fpReport released

2017-08-21 Thread leledumbo via fpc-pascal
> fpreport has been committed to FPC SVN: packages/fcl-report. 
> It should compile on windows, linux, freebsd and darwin.

From the wiki:
"An important use-case was a Linux server running in a container without X
libraries installed"

Yep, yep, yep. Finally I can replace my old statically designed reports :)



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/fpReport-released-tp5729564p5729578.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] H2pas tool vs others, C header translation

2017-08-21 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said:
> > I am looking to convert the GNU MPFR library header files, or hire 
> > someone on a bounty to do it if header translation is not so easy with 
> > h2pas and requires lots of hand work, and close checking.
> 
> I do all header translations with h2pas. Most of the time, I run the code
> first through gcc -E, which will take care of all macro magic. Usually h2pas
> has little trouble with the result.

Before everything I do a couple of substs with an editor, then instead of
gcc -E I use small pascal filterprograms to sort the symbols based on
heuristics.  Usually "clean" defines, structs, function calls and "rest".

The clear files I translate by h2pas, the rest manually or with pascal
programs, and then I stitch them together again. I try to preserve comments
as much as possible.

In the past, with very large headers, I did this restitching
semiautomatically, by inserting marker comments while splitting.

I tried all other headerconvertors, and didn't have a better result.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] StringOfChar for Unicode/Widestring

2017-08-21 Thread Bart
Hi,

Do we  have a StringOfChar function for UnicodeString/WideString in FreePascal?
I could not find it in 3.0.4RC1 (which may tell you more about me that fpc).

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

Re: [fpc-pascal] TStringHelper missing

2017-08-21 Thread Sven Barth via fpc-pascal
Am 21.08.2017 13:51 schrieb "Sven Barth" :
>
> Am 21.08.2017 08:23 schrieb "Michael Van Canneyt" :
> >
> >
> >
> > On Mon, 21 Aug 2017, Ryan Joseph wrote:
> >
> >> I’m trying to split a string by a delimiter and see there is a type
helper called TStringHelper (
https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.html). The
compiler version I’m using is "Free Pascal Compiler version 3.1.1
[2017/04/22] for i386” but when I include SysUtils the methods are not
found.
> >>
> >> For example:
> >>
> >> var
> >>  str: string;
> >>  parts: TStringArray;
> >>
> >> parts := str.Split(' ‘);
> >>
> >>
> >> What am I doing wrong?
> >
> >
> > Try
> >
> > var
> >   Str : AnsiString;
> > or
> >   Str : WideString;
> >
> > I believe the compiler has some trouble finding the helper if you use
the
> > 'string' alias. I think there is even a bugreport about it.
> > Sven Barth can confirm/deny this.
>
> I thought that was fixed? Except of course if $H- is used (which is the
default in all modes except the Delphi ones) cause then String = AnsiString.

String = ShortString in case of $H- of course -.-

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] TStringHelper missing

2017-08-21 Thread Sven Barth via fpc-pascal
Am 21.08.2017 08:23 schrieb "Michael Van Canneyt" :
>
>
>
> On Mon, 21 Aug 2017, Ryan Joseph wrote:
>
>> I’m trying to split a string by a delimiter and see there is a type
helper called TStringHelper (
https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.html). The
compiler version I’m using is "Free Pascal Compiler version 3.1.1
[2017/04/22] for i386” but when I include SysUtils the methods are not
found.
>>
>> For example:
>>
>> var
>>  str: string;
>>  parts: TStringArray;
>>
>> parts := str.Split(' ‘);
>>
>>
>> What am I doing wrong?
>
>
> Try
>
> var
>   Str : AnsiString;
> or
>   Str : WideString;
>
> I believe the compiler has some trouble finding the helper if you use the
> 'string' alias. I think there is even a bugreport about it.
> Sven Barth can confirm/deny this.

I thought that was fixed? Except of course if $H- is used (which is the
default in all modes except the Delphi ones) cause then String = AnsiString.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] H2pas tool vs others, C header translation

2017-08-21 Thread Michael Van Canneyt



On Sun, 20 Aug 2017, nore...@z505.com wrote:


Forgive me, I have forgotten, this may have been discussed before..

Is h2pas the latest tool to convert C headers to pas files?


For FPC, yes.



Is there a competing tool that does more, or is updated more?

I remember Bob Swart AFAIR had a popular tool for delphi.

And some people use multiple tools if one tool is giving them issues.

Is h2pas for example the one that is used for Mysql header translations 
and other major C headers?


Yes.



I am looking to convert the GNU MPFR library header files, or hire 
someone on a bounty to do it if header translation is not so easy with 
h2pas and requires lots of hand work, and close checking.


I do all header translations with h2pas. Most of the time, I run the code
first through gcc -E, which will take care of all macro magic. Usually h2pas
has little trouble with the result.

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

Re: [fpc-pascal] TStringHelper missing

2017-08-21 Thread Michael Van Canneyt



On Mon, 21 Aug 2017, Ryan Joseph wrote:


I’m trying to split a string by a delimiter and see there is a type helper called 
TStringHelper 
(https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.html). The compiler 
version I’m using is "Free Pascal Compiler version 3.1.1 [2017/04/22] for i386” 
but when I include SysUtils the methods are not found.

For example:

var
 str: string;
 parts: TStringArray;

parts := str.Split(' ‘);


What am I doing wrong?


Try

var
  Str : AnsiString;
or
  Str : WideString;

I believe the compiler has some trouble finding the helper if you use the
'string' alias. I think there is even a bugreport about it.
Sven Barth can confirm/deny this.

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