Double to string: _fcvt no longer works ???!!! 
Author Message
 Double to string: _fcvt no longer works ???!!!

Hi all.

As far, as I know, the wsprintf on WinCE cannot produce string
representations of floats/doubles (in other words - does not recognise the
"%f" switch).

So, I wrote myself a 'ftoa' routine, based on the call to stdlib function
'_fvct'.
Everything worked fine on various hardware until now, when to my amazement
( ;-( ) it showed, that the call to '_fvct' results in 'First-chance
exception in MyProgram.exe: 0xC0000005: Access Violation' (on Handheld PC
Cassiopea A-20, WCE 2.00, SH3).

I suspect that the reason may be the fact, that I uninstalled the old VC++
6.0 toolkit and moved everything to eVC++ 3.0.

So, there come the questions:

- is that really true, that '_fvct' no longer works on WCE 2.00/SH3 with
eVC++ 3.0?
- what to use instead?

Yours DW.



Sat, 05 Jun 2004 18:45:11 GMT  
 Double to string: _fcvt no longer works ???!!!
dear DW,

wsprintf with %lf works fine for me on IPaq (pocketPC).  
Is it only older ce versions that have the issue you are
trying to avoid?

Mike

Quote:
>-----Original Message-----
>Hi all.

>As far, as I know, the wsprintf on WinCE cannot produce
string
>representations of floats/doubles (in other words - does
not recognise the
>"%f" switch).

>So, I wrote myself a 'ftoa' routine, based on the call to
stdlib function
>'_fvct'.
>Everything worked fine on various hardware until now,

when to my amazement
Quote:
>( ;-( ) it showed, that the call to '_fvct' results
in 'First-chance
>exception in MyProgram.exe: 0xC0000005: Access Violation'
(on Handheld PC
>Cassiopea A-20, WCE 2.00, SH3).

>I suspect that the reason may be the fact, that I

uninstalled the old VC++
Quote:
>6.0 toolkit and moved everything to eVC++ 3.0.

>So, there come the questions:

>- is that really true, that '_fvct' no longer works on
WCE 2.00/SH3 with
>eVC++ 3.0?
>- what to use instead?

>Yours DW.

>.



Sat, 05 Jun 2004 21:23:04 GMT  
 Double to string: _fcvt no longer works ???!!!
Hi:

Quote:
> wsprintf with %lf works fine for me on IPaq (pocketPC).
> Is it only older ce versions that have the issue you are
> trying to avoid?

As I said before, the hardware in question is Cassiopea A-20 (Handheld PC,
WCE 2.00, SH3). Can't just ignore it, as we have many end users with such
devices, and are obliged to support them.

On this system:
    wsprintf(SomeString, L"%lf", SomeFloaf)
is equivalent to
    wsprintf(SomeString, L"%f", SomeFloaf)
as they both give the same result:

    SomeString == "f"

;-))))
Or maybe :-( ?

I have just re-written my 'ftoa' routine from scratch, but I have problems
with the inaccuracy of floating-point operations. As the result, I get
"1345.099" from 1345.1 :-(.

At the moment, I do not know how to get around this. Any suggestions?

Yours DW.
P.S. Microsoft probably claims no responsibility for ... etc., but this time
they should really pay fine (my company might even lose customers if the
problem was not spotted)!!! The low-level function works in one compiler and
stops in the next version. That is a real scandal!!!! How could one detect
all such problems???!!!!!



Sat, 05 Jun 2004 23:29:28 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
>At the moment, I do not know how to get around this. Any suggestions?

I would look at the C source for sprintf() - which basically maps to
vsprintf() - and floating point conversions. If you don't already have the
source for the standard C libs, here's a link to the source for NetBSD's C
lib: http://www.ajk.tele.fi/libc/code.html

T


Quote:
> Hi:

> > wsprintf with %lf works fine for me on IPaq (pocketPC).
> > Is it only older ce versions that have the issue you are
> > trying to avoid?

> As I said before, the hardware in question is Cassiopea A-20 (Handheld PC,
> WCE 2.00, SH3). Can't just ignore it, as we have many end users with such
> devices, and are obliged to support them.

> On this system:
>     wsprintf(SomeString, L"%lf", SomeFloaf)
> is equivalent to
>     wsprintf(SomeString, L"%f", SomeFloaf)
> as they both give the same result:

>     SomeString == "f"

> ;-))))
> Or maybe :-( ?

> I have just re-written my 'ftoa' routine from scratch, but I have problems
> with the inaccuracy of floating-point operations. As the result, I get
> "1345.099" from 1345.1 :-(.

> At the moment, I do not know how to get around this. Any suggestions?

> Yours DW.
> P.S. Microsoft probably claims no responsibility for ... etc., but this
time
> they should really pay fine (my company might even lose customers if the
> problem was not spotted)!!! The low-level function works in one compiler
and
> stops in the next version. That is a real scandal!!!! How could one detect
> all such problems???!!!!!



Sun, 06 Jun 2004 01:53:04 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:

> Hi:

> > wsprintf with %lf works fine for me on IPaq (pocketPC).
> > Is it only older ce versions that have the issue you are
> > trying to avoid?

> As I said before, the hardware in question is Cassiopea A-20 (Handheld PC,
> WCE 2.00, SH3). Can't just ignore it, as we have many end users with such
> devices, and are obliged to support them.

> On this system:
>     wsprintf(SomeString, L"%lf", SomeFloaf)
> is equivalent to
>     wsprintf(SomeString, L"%f", SomeFloaf)
> as they both give the same result:

>     SomeString == "f"

> ;-))))
> Or maybe :-( ?

> I have just re-written my 'ftoa' routine from scratch, but I have problems
> with the inaccuracy of floating-point operations. As the result, I get
> "1345.099" from 1345.1 :-(.

> At the moment, I do not know how to get around this. Any suggestions?

> Yours DW.
> P.S. < snipped >

Determine how many digits you are going to allow to the right of the
decimal point; let that number be n. Then take the absolute value of the
argument and add to it 0.5*pow10l(-(double)n). This will round the
argument value at the correct number of places. After converting the
result to characters make sure to truncate any beyond position n.

Norm



Sun, 06 Jun 2004 07:20:29 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
> I would look at the C source for sprintf() - which basically maps to
> vsprintf() - and floating point conversions. If you don't already have the
> source for the standard C libs, here's a link to the source for NetBSD's C
> lib: http://www.ajk.tele.fi/libc/code.html

Well, vsprintf() calls cvt() and cvt() is not provided with a source :-)

Yours DW.



Sun, 06 Jun 2004 17:39:43 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
> Determine how many digits you are going to allow to the right of the
> decimal point; let that number be n. Then take the absolute value of the
> argument and add to it 0.5*pow10l(-(double)n). This will round the
> argument value at the correct number of places. After converting the
> result to characters make sure to truncate any beyond position n.

I was following a similar path - I was adding 1 * ( 10^(-n) ) to the
absolute value of the number to be converted. Of course, it helped with
1345.1, but it will not work in every case (say: 1.2345, precision 3 - would
be: 1.234, and should be 1.235, BTW in both methods).

I was looking at the VC++ 6.0 includes and I found a function _fptostr()
(...\crt\src\_fptostr.c).

What is interesting, _fptostr() does the rounding on the final string, i.e.
it founds what character is at n-th position, if it is higher-or-equal than
'5' then produces an overflow of 1 and transports it backwards.
I wonder why they decided to round the output string, not the original
number? It seems a slower solution. Any wild guesses?

I am pretty concerned about the speed of my function, so any comment would
be appreciated.

Yours DW.



Sun, 06 Jun 2004 18:38:09 GMT  
 Double to string: _fcvt no longer works ???!!!
On Wed, 19 Dec 2001 11:38:09 +0100, "Dobieslaw Wroblewski"

<snip>

Quote:
>What is interesting, _fptostr() does the rounding on the final string, i.e.
>it founds what character is at n-th position, if it is higher-or-equal than
>'5' then produces an overflow of 1 and transports it backwards.
>I wonder why they decided to round the output string, not the original
>number? It seems a slower solution. Any wild guesses?

Bear in mind that a Float is an inherently innacurate way of storing a
number:  X = 2^n  where 'n' is stored.

It makes perfect sense to 'round' a number in its 'native form'.
ie: after it has become a true decimal number (a string).

BTW

- Floats multiply fast and add slowly,  Integers add fast and multiply
slowly.

Conversion from a number to a string (for those formats - not BCD)
involves considerable work - multiple divisions by 10

Quote:

>I am pretty concerned about the speed of my function, so any comment would
>be appreciated.

>Yours DW.



Sun, 06 Jun 2004 20:32:44 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
> It makes perfect sense to 'round' a number in its 'native form'.
> ie: after it has become a true decimal number (a string).

I did rounding of the output string. Bad thing is that it includes shifting
the output string left (if there is no overflow in the rounding, the
just-in-case leading zero should be removed). Hope it won't take too long in
practice.

The adventure is on, however ;-).

Take 0.0005 and precision 3 (i mean the places after the dot). The outcome
should be 0.001, and is 0, because 0.0005*10^(precision+1) == 4.999999999
;-).

So, I do the trick suggested by Norman and increase 0.0005*10^(precision+1)
by 0.05. It helps in this particular case, but 0.0004999 will also convert
to 0.001 and should be 0 :-(

Is it at all possible to do it right? My beliefs have gone away ;-)

Yours DW.



Sun, 06 Jun 2004 23:23:01 GMT  
 Double to string: _fcvt no longer works ???!!!
This is the classic IEEE inaccuracy problem.

This is the solution that I use in VB

   Q# = 10# ^ DP                           ' round it first
   N# = Int(Abs(N#) * Q# + 0.500001) / Q# * Sgn(N#) ' Must do Abs

Note that I am adding: 0.500001
Also that the sign is removed before calculation - and replaced
afterwards.

HTH

On Wed, 19 Dec 2001 16:23:01 +0100, "Dobieslaw Wroblewski"

Quote:

>> It makes perfect sense to 'round' a number in its 'native form'.
>> ie: after it has become a true decimal number (a string).

>I did rounding of the output string. Bad thing is that it includes shifting
>the output string left (if there is no overflow in the rounding, the
>just-in-case leading zero should be removed). Hope it won't take too long in
>practice.

>The adventure is on, however ;-).

>Take 0.0005 and precision 3 (i mean the places after the dot). The outcome
>should be 0.001, and is 0, because 0.0005*10^(precision+1) == 4.999999999
>;-).

>So, I do the trick suggested by Norman and increase 0.0005*10^(precision+1)
>by 0.05. It helps in this particular case, but 0.0004999 will also convert
>to 0.001 and should be 0 :-(

>Is it at all possible to do it right? My beliefs have gone away ;-)

>Yours DW.



Mon, 07 Jun 2004 18:50:34 GMT  
 Double to string: _fcvt no longer works ???!!!
I use _strpintf, which is defined as swprintf when UNICODE is defined.
It definitely supports %f. I know it doesn't support some features of
wsprintf. I don't know whether it solves the rounding problem
discussed in earlier threads. But it might be worth checking.

On Tue, 18 Dec 2001 11:45:11 +0100, "Dobieslaw Wroblewski"

Quote:

>Hi all.

>As far, as I know, the wsprintf on WinCE cannot produce string
>representations of floats/doubles (in other words - does not recognise the
>"%f" switch).

>So, I wrote myself a 'ftoa' routine, based on the call to stdlib function
>'_fvct'.
>Everything worked fine on various hardware until now, when to my amazement
>( ;-( ) it showed, that the call to '_fvct' results in 'First-chance
>exception in MyProgram.exe: 0xC0000005: Access Violation' (on Handheld PC
>Cassiopea A-20, WCE 2.00, SH3).

>I suspect that the reason may be the fact, that I uninstalled the old VC++
>6.0 toolkit and moved everything to eVC++ 3.0.

>So, there come the questions:

>- is that really true, that '_fvct' no longer works on WCE 2.00/SH3 with
>eVC++ 3.0?
>- what to use instead?

>Yours DW.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com



Sun, 13 Jun 2004 23:19:13 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
> I use _strpintf, which is defined as swprintf when UNICODE is defined.
> It definitely supports %f.

For Cassiopea A20 - it definitely doesn't. The result is "f" :-)

Yours DW.



Sun, 20 Jun 2004 15:40:07 GMT  
 Double to string: _fcvt no longer works ???!!!
It works on my PA-2400, which is pretty close to your A20 (uses SH3
CPU and runs CE 2.00). I've been using that construct for a few years
with no problem. I've built my app using VC 5 plus CE tools (toolkits
and SDKs), VC 6 plus CE tools, and eVT plus HPC (CE 2.0) SDK.

Where did you get the HPC (CE 2.0) SDK? I've heard rumors that the one
available from Microsoft's web site doesn't really work with eVT, but
have heard no more details. I'm using a copy from an old MSDN CD.

I _just_ noticed a type in my earlier note: _strprintf should be
_stprintf.

(did you leave out the %?)

On Wed, 2 Jan 2002 08:40:07 +0100, "Dobieslaw Wroblewski"

Quote:

>> I use _strpintf, which is defined as swprintf when UNICODE is defined.
>> It definitely supports %f.

>For Cassiopea A20 - it definitely doesn't. The result is "f" :-)

>Yours DW.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com



Mon, 21 Jun 2004 23:27:43 GMT  
 Double to string: _fcvt no longer works ???!!!

Quote:
> It works on my PA-2400, which is pretty close to your A20 (uses SH3
> CPU and runs CE 2.00). I've been using that construct for a few years
> with no problem. I've built my app using VC 5 plus CE tools (toolkits
> and SDKs), VC 6 plus CE tools, and eVT plus HPC (CE 2.0) SDK.

I just realised that you meant swprintf. I was using wsprintf and this one
did not work.
I will check when I have a free time.

Quote:
> Where did you get the HPC (CE 2.0) SDK? I've heard rumors that the one
> available from Microsoft's web site doesn't really work with eVT, but
> have heard no more details. I'm using a copy from an old MSDN CD.

I am not sure where I got this from.

Yours DW.



Mon, 21 Jun 2004 23:55:24 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Long long and long double

2. long double to string & string to long double

3. Long double didn't work over 1e+308

4. Long double didn't work over 1e+308

5. Long double to string --

6. Need function to convert float/double/long to string using a specified format

7. convert string to long double - problem

8. convert string to long, and long to string

9. can long double be less precise than double?

10. long long integer and double precision number

11. addition long values to long double value ?

12. epsilon for float, double long double

 

 
Powered by phpBB® Forum Software