Sign in

username:

password:



Not a member?

Search adsp



Search tips

Subscribe to adsp



adsp by Keywords

AD1819 | AD7332 | ADSP-2106 | ADSP-21060 | ADSP-21065L | ADSP-2116 | ADSP-21160M | ADSP-2181 | ADSP-218x | ADSP-219 | ADSP-2199 | ADSP219 | BF531 | BF532 | BF533 | BF535 | Blackfin | FFT | JTAG | LDF | SDRAM | SHARC | SPORT | UART | VDSP++ | VisualDSP

Ads

Discussion Groups

Technical discussions related to Analog Devices DSPs (including Blackfin, TigerSHARC, SHARC and ADSP-21xx DSPs).

  

Post a new Thread

Pls Help - sathish chandra - May 17 23:17:20 2007



Hello all
   
  Below I have written a code in C.
   
  Now the problem is 
   
  The value "2.60" copying to szData using a string function.
  After copying the function atof (convert string to double) i am using. But the result what i
am getting in the variable dlData not the expected one.
  I am getting : 2.6000000000000001. The 1 in the last value is the error one. How i can avoid
that.

  #include "stdafx.h"
#include "NumberTest.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <float.h>
  #ifdef _DEBUG
#define new DEBUG_NEW
#endif

main()
{
 
 double dlData;

 char szData[25];

  strcpy(szData," 2.60");

  dlData = atof(szData);
    printf("%lf",dlData);
 
}

  Thanks in Advance
   
  sathish

---------------------------------
 Office firewalls, cyber cafes, college labs, don't allow you to download CHAT? Here's a
solution! 


(You need to be a member of adsp -- send a blank email to adsp-subscribe@yahoogroups.com )

Re: Pls Help - Mike Rosing - May 18 9:59:46 2007

On Thu, 17 May 2007, sathish chandra wrote:

> Hello all
>
>   Below I have written a code in C.
>
>   Now the problem is
>
>   The value "2.60" copying to szData using a string function.
>   After copying the function atof (convert string to double) i am using. But the result
what i am getting in the variable dlData not the expected one.
>   I am getting : 2.6000000000000001. The 1 in the last value is the error one. How i can
avoid that.

that's roundoff when going back.  In other words, you convert string to
double, then to see it you have go double back to string.  The conversion
going back has roundoff, there's no problem with the value in ram.

You can check that by dumping the raw binary data and looking up the
format in the manual and do the conversion by hand.

Patience, persistence, truth,
Dr. mike



(You need to be a member of adsp -- send a blank email to adsp-subscribe@yahoogroups.com )

Re: Pls Help - Nguyen Hoan Hoang - May 18 17:22:30 2007

you can do
     printf("%.2f", dlData);

it will give you them same as your original string
sathish chandra wrote:
> Hello all
>  
> Below I have written a code in C.
>  
> Now the problem is
>  
> The value "2.60" copying to *szData* using a string function.
> After copying the function *atof* (convert string to double) i am 
> using. But the result what i am getting in the variable *dlData* not 
> the expected one.
> I am getting : 2.6000000000000001. The 1 in the last value is the 
> error one. How i can avoid that.
>  
>  
>  
> #include "stdafx.h"
> #include "NumberTest.h"
> #include <stdlib.h>
> #include <math.h>
> #include <stdio.h>
> #include <float.h>
> #ifdef _DEBUG
> #define new DEBUG_NEW
> #endif
>  
>
> main()
> {
>  
>  double dlData;
>  
>  
>  char szData[25];
>  
>   
>   strcpy(szData," 2.60"); 
>   
>   
>   dlData = atof(szData);
>   printf("%lf",dlData);
>  
> }
>  
>  
>  
> Thanks in Advance
>  
> sathish
>
> ------------------------------------------------------------------------
> Office firewalls, cyber cafes, college labs, don't allow you to 
> download CHAT? Here's a solution! 
>
<http://us.rd.yahoo.com/mail/in/ymessenger/*http://in.messenger.yahoo.com/webmessengerpromo.
php>



(You need to be a member of adsp -- send a blank email to adsp-subscribe@yahoogroups.com )