Board index » delphi » strtofloat and extended problem

strtofloat and extended problem

I'm trying to convert a string using strtofloat, (D7) which gives an
extended value. I need to use this value in a function that I havent the
source code for - it requires a double and the compiler complains during
debug stepping, but funnily enough, not during running under the IDE!,
why is this?
How can I typecast the number into a double? (Or am I missing
something!)
Thanks
Chris
 

Re:strtofloat and extended problem


Quote
Chris Lock wrote:
> I'm trying to convert a string using strtofloat, (D7) which gives an
> extended value. I need to use this value in a function that I havent the
> source code for - it requires a double and the compiler complains during
> debug stepping, but funnily enough, not during running under the IDE!,
> why is this?
> How can I typecast the number into a double? (Or am I missing
> something!)

You can't typecast an Extended to a Double; their sizes don't match.
Fortunately for you, it's usually not necessary to do such a cast since
the compiler will automatically convert between them. If you assign an
Extended value to a Double variable, it will be converted.

Please show your code, including any relevant variable declarations and
the declaration of this mysterious function you mention. Also specify
what, specifically, Delphi complains about. (The compiler cannot
complain during debugging. The compiler isn't running while debugging,
but the de{*word*81} is. Both are part of the IDE.)

--
Rob

Re:strtofloat and extended problem


On Sat, 24 May 2003 20:46:03 GMT, "Chris Lock"

Quote
<chris.l...@kentdesigns.co.uk> wrote:
>I'm trying to convert a string using strtofloat, (D7) which gives an
>extended value. I need to use this value in a function that I havent the
>source code for - it requires a double and the compiler complains during
>debug stepping, but funnily enough, not during running under the IDE!,
>why is this?
>How can I typecast the number into a double? (Or am I missing
>something!)

If the function wants a value passed to it, then an extended will be
automatically converted.  If it wants a var parameter, then just
assign the result of StrToFloat to a double; the conversion is done
automatically.

Duncan Murdoch

Re:strtofloat and extended problem


Quote
Duncan Murdoch wrote:
> On Sat, 24 May 2003 20:46:03 GMT, "Chris Lock"
> <chris.l...@kentdesigns.co.uk> wrote:

>>I'm trying to convert a string using strtofloat, (D7) which gives an
>>extended value. I need to use this value in a function that I havent the
>>source code for - it requires a double and the compiler complains during
>>debug stepping, but funnily enough, not during running under the IDE!,
>>why is this?
>>How can I typecast the number into a double? (Or am I missing
>>something!)

> If the function wants a value passed to it, then an extended will be
> automatically converted.  If it wants a var parameter, then just
> assign the result of StrToFloat to a double; the conversion is done
> automatically.

The compiler may warn you when you're losing precision in a conversion, e.g.
by converting Extended to Double.  It's simply an informational message.

Re:strtofloat and extended problem


On further investigation, maybe this isnt the problem after all.
It doesnt matter whether maxraxis is a double or extended (the chart
procedure expects a double).
I just cant understand why I get the failure message by single stepping
and not on a run.
I have integrated debugging and 'stop on delphi exceptions' enabled.

Code below:-

I am creating a form containing a graph (Teechart) as follows...

procedure TForm4.LookGraphButClick(Sender: TObject);
var
modal:Tform5;
begin
if Afile_results<>nil then   // if data exists call up graph
begin
 modal:=Tform5.create(application);
 try
 modal.ShowModal;
 finally
 modal.free;
end;
end;
end;

// this is the form containing the Tchart

procedure TForm5.FormCreate(Sender: TObject);
var
ser,channels,x,I:integer;
maxLaxis,maxRaxis:Double;//extended;
minLaxis,minRaxis:extended;
Raxis_used:boolean;
s:string;
begin
maxraxis:=10.6; // TEST ONLY

fails on next step with Einvalidop with message 'invalid floating point
operation'
only during single stepping.

Chart1.rightAxis.SetMinMax( 0,maxraxis+10.0  ) ; // pressure values TEST
ONLY

************************************************************************

Thanks again
Chris

Re:strtofloat and extended problem


Another theory - Is it something to do with accessing the chart during
the oncreate method of the form?
Chris

Re:strtofloat and extended problem


Quote
Rob Kennedy wrote in message ...
>You can't typecast an Extended to a Double; their sizes don't match.

Actually, you can. Contrary to what Bruce Roberts (I think) and I
recently exchanged, typecasting is not limited to interpreting the
same memory contents as differently typed values. There are two
forms of typecasting: variable and value. Laying a different perception
over memory constitutes variable typecasting; making a Double out
of an Extended requires value typecasting. It's mainly applicable
to floating point formats, where the approximation may deteriorate
without too many ill effects. Autoconverting a real to an integer
as some language allow is more questionable, but "demoting" a
10-byte float to an 8-byte float is relatively harmless, especially
as it was imprecise to begin with. (The term "demoting" is used as
opposed to the mechanism of "promotion" in C, where parameters to
as-yet undeclared functions are widened accoring to predefined rules.)

Groetjes,
Maarten Wiltink

Re:strtofloat and extended problem


In article <3ed0aa65$0$49113$e4fe5...@news.xs4all.nl>, "Maarten Wiltink"

Quote
<maar...@kittensandcats.net> writes:
>making a Double out
>of an Extended requires value typecasting.

Wouldn't that be done via the FPU, loading as an Extended and reading as a
double with a registry shuffle or something between the load & read ?

Alan Lloyd
alangll...@aol.com

Re:strtofloat and extended problem


Quote
AlanGLLoyd wrote in message

<20030525123204.29002.00000...@mb-m21.aol.com>...

Quote
>In article <3ed0aa65$0$49113$e4fe5...@news.xs4all.nl>, "Maarten Wiltink"
><maar...@kittensandcats.net> writes:

>>making a Double out
>>of an Extended requires value typecasting.

>Wouldn't that be done via the FPU, loading as an Extended and reading as a
>double with a registry shuffle or something between the load & read ?

The disassembly windows says

fld tbyte ptr [a]
fstp qword ptr [b]

so yes, that certainly looks like it. (D3.)

Groetjes,
Maarten Wiltink

Re:strtofloat and extended problem


"Chris Lock" <chris.l...@kentdesigns.co.uk> skrev i melding
news:kZSza.75790$UJ5.50122@news-lhr.blueyonder.co.uk...

Quote
> On further investigation, maybe this isnt the problem after all.
> It doesnt matter whether maxraxis is a double or extended (the chart
> procedure expects a double).
> I just cant understand why I get the failure message by single stepping
> and not on a run.
> I have integrated debugging and 'stop on delphi exceptions' enabled.

This is commonly encountered in Delphi - float operations cause random
problems especially within painting routines, to my experience. As you say -
when running, there is no problems. There are many things that may be a
problem when stepoping, e.g. when threads are involved.

--
Regards,

Bj?rge S?ther
bjorge@haha_itte.no
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.

Other Threads