News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

C runtime function question.

Started by hutch--, August 11, 2018, 01:31:43 AM

Previous topic - Next topic

hutch--

I am looking for a pair of floating point conversions from the C runtime library and the two I have found are as follows.

    double atof( 
       const char *str   
    );

    char *_fcvt(   
       double value, 
       int count, 
       int *dec, 
       int *sign   
    ); 

I don't claim to be fully up to date with C runtime functions and while I can probably get these to work, I would be interested in any viable suggestions if there are any that are better suited to do the two way conversions.

jj2007

There is really no lack of atof alternatives :lol:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/atodbl-atodbl-l-atoldbl-atoldbl-l-atoflt-atoflt-l
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/atof-atof-l-wtof-wtof-l

https://stackoverflow.com/questions/98586/where-can-i-find-the-worlds-fastest-atof-implementation

Of course, there are faster and more precise solutions around:Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz (SSE4)

152829  cycles for 100 * CRT atof
23178   cycles for 100 * MB Val()

151248  cycles for 100 * CRT atof
23024   cycles for 100 * MB Val()

151656  cycles for 100 * CRT atof
24375   cycles for 100 * MB Val()

152207  cycles for 100 * CRT atof
23248   cycles for 100 * MB Val()

151453  cycles for 100 * CRT atof
23178   cycles for 100 * MB Val()

36      bytes for CRT atof
34      bytes for MB Val()

ST0     1234567890.123456716
ST0     1234567890.123456789

hutch--

atof already works, I got it from the MSDN links before you posted them.

I think I have the two functions working, just doing the text formatting from fcvt.

zedd151

 :biggrin:


AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (SSE4)

127115  cycles for 100 * CRT atof
21107   cycles for 100 * MB Val()

126984  cycles for 100 * CRT atof
20389   cycles for 100 * MB Val()

126807  cycles for 100 * CRT atof
21040   cycles for 100 * MB Val()

127579  cycles for 100 * CRT atof
21366   cycles for 100 * MB Val()

127227  cycles for 100 * CRT atof
20325   cycles for 100 * MB Val()

36      bytes for CRT atof
34      bytes for MB Val()

ST0     1234567890.123456716
ST0     1234567890.123456789

--- ok ---


hutch--

#4
Like most of the suggestions, they are not much use to me at the moment.

None the less, with a change to the floating point to ascii conversion, all is well and up and running reliably as a general purpose pair of conversions.  :P