Board index » delphi » Exporting Constants

Exporting Constants

Hey,

I am creating a Scientific Calculator, and was wondering if it was possible
to export constants from a DLL. The values for 'pi' and 'e' are defined in
the DLL containing the functions, but I also wish to use them in the main
project file. Can I do this, or do I have to use functions such as getPI(),
getE(), etc?

Thanks,

Murdoc

 

Re:Exporting Constants


Quote
Murdoc wrote in message ...
>Hey,

>I am creating a Scientific Calculator, and was wondering if it was
possible
>to export constants from a DLL. The values for 'pi' and 'e' are defined in
>the DLL containing the functions, but I also wish to use them in the main
>project file. Can I do this, or do I have to use functions such as
getPI(),
>getE(), etc?

DLLs can export only code, not data. Does that answer your question?

Groetjes,
Maarten Wiltink

Re:Exporting Constants


JRS:  In article <ap23i4$m...@gnamma.connect.com.au>, seen in
news:alt.comp.lang.borland-delphi, Murdoc <murdo...@hotmail.com> posted
at Mon, 21 Oct 2002 14:30:59 :-

Quote
>I am creating a Scientific Calculator, and was wondering if it was possible
>to export constants from a DLL. The values for 'pi' and 'e' are defined in
>the DLL containing the functions, but I also wish to use them in the main
>project file. Can I do this, or do I have to use functions such as getPI(),
>getE(), etc?

You should be using the predefined Pi which has been in Delphi since
TurboPascal 4 at least; you cannot define it more accurately, and
perhaps not as accurately, yourself.

The value of e can be obtained fairly rapidly as Exp(1.0), in all Wirth-
compatible Pascals.

Do not cross-post into news:borland.*; if it were to work properly, it
would be against Borland Guidelines.  The experts will not see your
article in b.p.d.w.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 For news:borland.*, use their server newsgroups.borland.com ; but first read
 Guidelines <URL:http://www.borland.com/newsgroups/guide.html> ff. with care.

Re:Exporting Constants


In article <ap47va$lt...@news1.xs4all.nl>, "Maarten Wiltink"

Quote
<maar...@kittensandcats.net> writes:
>And pi can be obtained fairly rapidly as 4*arctan(1).

Pi can be obtained roughly (to 1 in 10^^7) from ...

  355/113

Enginers just remember it to that sort of accuracy - 3.1415926 <g>

Alan Lloyd
alangll...@aol.com

Re:Exporting Constants


Quote
Dr John Stockton wrote in message ...

[...]

Quote
>You should be using the predefined Pi which has been in Delphi since
>TurboPascal 4 at least; you cannot define it more accurately, and
>perhaps not as accurately, yourself.

>The value of e can be obtained fairly rapidly as Exp(1.0), in all Wirth-
>compatible Pascals.

And pi can be obtained fairly rapidly as 4*arctan(1). Not sure
if that's Wirth-compatible.

The naive way to compute pi like that probably loses some accuracy
that could be retained by simply adding two to the exponent and
leaving the mantissa alone. Was that what you meant?

The smart way is to ask the numerical coprocessor to store pi into
TOS. Or is that cheating, or unbearably Intel-oriented, or otherwise
reprehensible?

Groetjes,
Maarten Wiltink

Re:Exporting Constants


JRS:  In article <ap47va$lt...@news1.xs4all.nl>, seen in
news:alt.comp.lang.borland-delphi, Maarten Wiltink
<maar...@kittensandcats.net> posted at Tue, 22 Oct 2002 21:12:40 :-

Quote
>Dr John Stockton wrote in message ...
>[...]
>>You should be using the predefined Pi which has been in Delphi since
>>TurboPascal 4 at least; you cannot define it more accurately, and
>>perhaps not as accurately, yourself.

>>The value of e can be obtained fairly rapidly as Exp(1.0), in all Wirth-
>>compatible Pascals.

>And pi can be obtained fairly rapidly as 4*arctan(1). Not sure
>if that's Wirth-compatible.

It will be.  It also worked in Algol 60.  But it is silly to get Pi that
way in Delphi when Pi has been a standard "function" in Borland's
Pascals since time immemorial, with the optimum extended value.

Someone might check/know whether "compiler magic" applies so that
writing Pi codes not as a call but as a const; if necessary,   var Pi :
extended ; ... Pi := System.Pi ;    could be used.

Quote
>The naive way to compute pi like that probably loses some accuracy
>that could be retained by simply adding two to the exponent and
>leaving the mantissa alone. Was that what you meant?

No; I meant to use System.Pi.  But I cannot believe that, in IEEE 754
(854?) arithmetic, 4* might not in all cases be exact.

Quote
>The smart way is to ask the numerical coprocessor to store pi into
>TOS. Or is that cheating, or unbearably Intel-oriented, or otherwise
>reprehensible?

Delphi assumes Intel & FPU, I believe.  Compiler writers should know
whether it is more efficient to load the value from the FPU or to fetch
the bit pattern from somewhere in the EXE; it may depend on the target
system.

BTW, I've not checked in Delphi; but in Pascal there was no digit
sequence S such that   {System.}Pi = 3.S ;  it was always at least one
LSB out.

I used :    pi = 3.1415926535897932385 + 6.5E-19 {!} ;
since I needed it as a true const in order to do
   const TwoPi = 2.0 * pi ;

Using Double arithmetic, the best approximation for Pi that I can find
is 80143857/25510582.  But e is harder to approximate fractionally.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Re:Exporting Constants


Quote
Dr John Stockton wrote in message <3O7RvMBxUnt9E...@merlyn.demon.co.uk>...

[...]

Quote
>I used :    pi = 3.1415926535897932385 + 6.5E-19 {!} ;

How... curious. That looks _not at all_ like it adds up to
3.141592653589793238462...

Groetjes,
Maarten Wiltink

Re:Exporting Constants


JRS:  In article <ap6u02$5...@news1.xs4all.nl>, seen in
news:alt.comp.lang.borland-delphi, Maarten Wiltink
<maar...@kittensandcats.net> posted at Wed, 23 Oct 2002 21:39:55 :-

Quote
>Dr John Stockton wrote in message <3O7RvMBxUnt9E...@merlyn.demon.co.uk>...
>[...]
>>I used :    pi = 3.1415926535897932385 + 6.5E-19 {!} ;

>How... curious. That looks _not at all_ like it adds up to
>3.141592653589793238462...

It did in whatever TP/BP I was using at the time; it still does, today,
in BP7, but not in D3.

Tests show that a smaller, but non-zero-correction is required in D3, if that
number of figures is provided; but that giving more figures gives the right
answer (which it does not in BP) :

C:\EPHEMERA>type $44.pas
 const
 Pi   = 3.1415926535897932385 ;
 Long = 3.141592653589793238462643383279 ;
 MyPi = 3.1415926535897932385 + 2.5E-19 {!} ;
 begin writeln ;
   writeln('System.Pi ',            System.Pi:1:25) ;
   writeln('       Pi ',                   Pi:1:25) ;
   writeln('     Long ',                 Long:1:25) ;
   writeln('     MyPi ',                 MyPi:1:25) ;
   writeln('  Pi-System.Pi ',    Pi-System.Pi,    Pi=System.Pi:6) ;
   writeln('Long-System.Pi ',  Long-System.Pi,  Long=System.Pi:6) ;
   writeln('MyPi-System.Pi ',  MyPi-System.Pi,  MyPi=System.Pi:6) ;
   end.

C:\EPHEMERA>dcc $44

C:\EPHEMERA>"C:\Program Files\Borland\Delphi 3\BIN\dcc32" -cc $44
Delphi for Win32  Version 10.0  Copyright (c) 1983,97 Borland International
$44.pas(15)
16 lines, 0.09 seconds, 12164 bytes code, 1377 bytes data.

C:\EPHEMERA>

C:\EPHEMERA>$44

System.Pi 3.1415926535897932400000000
       Pi 3.1415926535897932400000000
     Long 3.1415926535897932400000000
     MyPi 3.1415926535897932400000000
  Pi-System.Pi -2.16840434497101E-0019 FALSE
Long-System.Pi  0.00000000000000E+0000  TRUE
MyPi-System.Pi  0.00000000000000E+0000  TRUE

This seems consistent with the view that the best way of providing the
value of Pi in a Pascal/Delphi program is to use the characters "Pi".

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
  <URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
  <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Other Threads