Re: [fpc-pascal] Inconsistent results currency - extended ?

2014-04-29 Thread LacaK



  Your code does not even compile on
my 2.6.4 installation (no Lazarus).

  Where does the currtostr function come from?
Apparently from sysutils unit.
  

Yes from SysUtils


How is it 'included' without any uses clause?
I found no option that automatic 
add unit sysutils.


  Could you give us a source and a compilation command line
that does not require Lazarus use?
  

Source code attached.
Command line parameters:  -MObjFPC -Scghi -O1 -Twin32 -Pi386 -g -gl 
-vewnhi -Filib\i386-win32 -Fu. -FUlib\i386-win32 -l
(taken from Lazarus as I never have used only standalone compiler , 
without Lazarus IDE)


= PROGRAM ==
program test_Currency;
{$mode objfpc}{$H+}
uses
 {$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
 {$ENDIF}{$ENDIF}
 SysUtils;

var
 s: string;
 c: currency;
 e: extended;
 d: double;
 i64: int64;

begin
 c:=-92233720368547;
 d:=-92233720368547;
 e:=c;
 i64:=PInt64(@c)^;

 writeln('CW=', Get8087cw());
 writeln('currency=', c);
 writeln('extended=', e);
 writeln('string=', currtostr(c));
 writeln('int64=', i64);
 writeln('double=', d);
 readln;
end.


When I compile on Win98 and run (it does not depend if it is ran on 
Win98 or XP or Vista) output is same:

=== OUTPUT 1 ===
CW=4978
currency=-9.223372036854699520E+13
extended=-9.2233720368546995E+0013
string=-92233720368546,9952
int64=-922337203685469952
double=-9.22337203685470E+013

It seems (based on "i64" variable), that currency "c" is wrong 
initialised with "-92233720368546.9952"

On other side double is correct "-92233720368547"

When I compile on Win Vista and run (it does not depend if it is Win98 
or XP or Vista) output is correct (as expected):

=== OUTPUT 2 
CW=4978
currency=-9.22337203685470E+13
extended=-9.2233720368547000E+0013
string=-92233720368547
int64=-92233720368547
double=-9.22337203685470E+013


Thanks
-Laco.


Pierre Muller

  

-Message d'origine-
De : fpc-pascal-boun...@lists.freepascal.org [mailto:fpc-pascal-
boun...@lists.freepascal.org] De la part de LacaK
Envoyé : mardi 29 avril 2014 10:23
À : FPC-Pascal users discussions
Objet : [fpc-pascal] Inconsistent results currency - extended ?

Hi,
I catch strange behavior, which I can not understand ;-)

I have 2 PC on both I have installed Lazarus 1.2.2 + FPC 2.6.4
(official
release)

1st PC has Windows 98 2nd PC has Windows Vista (32 bit)

I have this program:
=
var
  c: currency;
  e: extended;
begin
  c:=-92233720368547;
  e:=c;
  writeln('CW=', Get8087cw(), ' currency=', c, ' extended=', e, '
string=', currtostr(c));
=

When I compile on 1st PC (Win98) and run it on 1st or 2nd PC I get this
result:
CW=4978 currency=-9.223372036854699520E+13
extended=-9.2233720368546995E+0013 string=-92233720368546,9952

When I compile on 2nd PC (Win Vista) and run on 1st or 2nd PC I get
(expected) result:
CW=4978 currency=-9.22337203685470E+13
extended=-9.2233720368547000E+0013 string=-92233720368547

How is it possible?
Is compiled code somehow affected by platform on which is compilation
performed?

Thanks
-Laco.

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


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

  


program test_Currency;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  SysUtils;

var
  s: string;
  c: currency;
  e: extended;
  d: double;
  i64: int64;

begin
  c:=currency(-92233720368547);
  d:=-92233720368547;
  e:=c;
  i64:=PInt64(@c)^;

  writeln('CW=', Get8087cw());
  writeln('currency=', c);
  writeln('extended=', e);
  writeln('string=', currtostr(c));
  writeln('int64=', i64);
  writeln('double=', d);
  readln;
end.

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

Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Mark Morgan Lloyd

Paul Breneman wrote:

On 04/29/2014 04:59 AM, Michael Schnell wrote:

On 04/29/2014 10:34 AM, Mark Morgan Lloyd wrote:


Or possibly building the source for a dll/so on the fly.

A nice and funny idea combining the benefits of scripting and compiling.
A little bit similar to the "ahead of time" reatlime compiler in a Java
or CIL framework.

Did somebody ever indeed put something like this to work ?


In my case it was a MIDI filter: display messages in a debugging window 
as they came in, edit the library to handle them specially, reload and 
repeat. The result was a program that could transpose multiple manuals 
and switch between transpositions depending on button presses, but where 
the message emitted by each button was very much dependant on the 
keyboard model and manufacturer.


I'm sure there's a better example.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Paul Breneman

On 04/29/2014 04:59 AM, Michael Schnell wrote:

On 04/29/2014 10:34 AM, Mark Morgan Lloyd wrote:


Or possibly building the source for a dll/so on the fly.

A nice and funny idea combining the benefits of scripting and compiling.
A little bit similar to the "ahead of time" reatlime compiler in a Java
or CIL framework.

Did somebody ever indeed put something like this to work ?


That sounds like an interesting project.  Maybe I should add such an 
example on one of these pages (that contain mini Free Pascal distributions):

  www.CtrlTerm.com
  www.TurboControl.com/monitor.htm

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


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Martin Frb

On 29/04/2014 02:58, Craig Peterson wrote:

Hi guys,

Does Free Pascal or any of the included packages have a way to create a
descendant of a class at runtime?  Before anyone tells me it's a bad
idea, I know.  I have an existing class-based registration scheme that
I'm adding some dynamically loaded plugins to and the alternatives are
all messier.



Well. Nothing is impossible. But somethings are not advice-able.

It can be done. But it must be checked with every Version of FPC, it may 
break on every new version.
Same it must be checked with ever compiler setting, and may break with 
any of them.


Also: inherited calls will not work in such cases, and you need to write 
very messy code, in order for it to work with such a self build class.


The basic is:

PPointer = ^Pointer

PPointer(SomeObject)^  contains the address of the class data (size and 
content can be found in the RTL).


You can copy and modify that. You also must copy the VMT, and that means 
you need to know how many virtual methods you declared (there is no 
count stored / so you must know). And you must disable any optimizations 
to class structure/ vmt optimizations.


All in all, you will have really hard to read and easy to break code.


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


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Mark Morgan Lloyd

Michael Schnell wrote:


A little bit similar to the "ahead of time" reatlime


:-)

 compiler in a Java

or CIL framework.

Did somebody ever indeed put something like this to work ?


I've got something where I can recompile a .so and the main program 
reloads it automatically (usually) without crashing. To clarify: it 
fails to reload on occasion possibly because it drops a signal but I've 
not seen it crash since I'm careful about when the swap is attempted.


I've not tried building something into the main program to reconstruct 
the source of the library and recompile it. I'd note that I'm being 
paranoid about protecting the interface- lots of magic numbers- and that 
the .so is always generated with a unique name.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Inconsistent results currency - extended ?

2014-04-29 Thread Pierre Free Pascal
  Your code does not even compile on
my 2.6.4 installation (no Lazarus).

  Where does the currtostr function come from?
Apparently from sysutils unit.
How is it 'included' without any uses clause?
I found no option that automatic 
add unit sysutils.

  Could you give us a source and a compilation command line
that does not require Lazarus use?


Pierre Muller

> -Message d'origine-
> De : fpc-pascal-boun...@lists.freepascal.org [mailto:fpc-pascal-
> boun...@lists.freepascal.org] De la part de LacaK
> Envoyé : mardi 29 avril 2014 10:23
> À : FPC-Pascal users discussions
> Objet : [fpc-pascal] Inconsistent results currency - extended ?
> 
> Hi,
> I catch strange behavior, which I can not understand ;-)
> 
> I have 2 PC on both I have installed Lazarus 1.2.2 + FPC 2.6.4
> (official
> release)
> 
> 1st PC has Windows 98 2nd PC has Windows Vista (32 bit)
> 
> I have this program:
> =
> var
>   c: currency;
>   e: extended;
> begin
>   c:=-92233720368547;
>   e:=c;
>   writeln('CW=', Get8087cw(), ' currency=', c, ' extended=', e, '
> string=', currtostr(c));
> =
> 
> When I compile on 1st PC (Win98) and run it on 1st or 2nd PC I get this
> result:
> CW=4978 currency=-9.223372036854699520E+13
> extended=-9.2233720368546995E+0013 string=-92233720368546,9952
> 
> When I compile on 2nd PC (Win Vista) and run on 1st or 2nd PC I get
> (expected) result:
> CW=4978 currency=-9.22337203685470E+13
> extended=-9.2233720368547000E+0013 string=-92233720368547
> 
> How is it possible?
> Is compiled code somehow affected by platform on which is compilation
> performed?
> 
> Thanks
> -Laco.
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Inconsistent results currency - extended ?

2014-04-29 Thread Michael Schnell
"Real" values are not supposed to be exact. They are depending on the 
hardware and other stuff by design.


"currency" is a funny beast :)

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


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Michael Schnell

On 04/29/2014 10:34 AM, Mark Morgan Lloyd wrote:


Or possibly building the source for a dll/so on the fly.
A nice and funny idea combining the benefits of scripting and compiling. 
A little bit similar to the "ahead of time" reatlime compiler in a Java 
or CIL framework.


Did somebody ever indeed put something like this to work ?

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


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Mark Morgan Lloyd

Michael Schnell wrote:

On 04/29/2014 03:58 AM, Craig Peterson wrote:

Does Free Pascal or any of the included packages have a way to create a
descendant of a class at runtime?
Only a script interpreter could possibly create a Type at runtime. 
AFAIK, there is a Pascal script interpreter usable with fpc. And in a 
script I don't think this is a bad idea (but I am not an expert with 
scripts).


Or possibly building the source for a dll/so on the fly. However the 
entire custom class would have to be hidden in the library, i.e. 
couldn't be exposed by the interface since this would have to be known 
when the main program was compiled.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Inconsistent results currency - extended ?

2014-04-29 Thread LacaK

Hi,
I catch strange behavior, which I can not understand ;-)

I have 2 PC on both I have installed Lazarus 1.2.2 + FPC 2.6.4 (official 
release)


1st PC has Windows 98 2nd PC has Windows Vista (32 bit)

I have this program:
=
var
 c: currency;
 e: extended;
begin
 c:=-92233720368547;
 e:=c;
 writeln('CW=', Get8087cw(), ' currency=', c, ' extended=', e, ' 
string=', currtostr(c));

=

When I compile on 1st PC (Win98) and run it on 1st or 2nd PC I get this 
result:
CW=4978 currency=-9.223372036854699520E+13 
extended=-9.2233720368546995E+0013 string=-92233720368546,9952


When I compile on 2nd PC (Win Vista) and run on 1st or 2nd PC I get 
(expected) result:
CW=4978 currency=-9.22337203685470E+13 
extended=-9.2233720368547000E+0013 string=-92233720368547


How is it possible?
Is compiled code somehow affected by platform on which is compilation 
performed?


Thanks
-Laco.

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


Re: [fpc-pascal] Create class descendant at runtime?

2014-04-29 Thread Michael Schnell

On 04/29/2014 03:58 AM, Craig Peterson wrote:

Does Free Pascal or any of the included packages have a way to create a
descendant of a class at runtime?
Only a script interpreter could possibly create a Type at runtime. 
AFAIK, there is a Pascal script interpreter usable with fpc. And in a 
script I don't think this is a bad idea (but I am not an expert with 
scripts).


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