Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] from string to double in CCS C

Status
Not open for further replies.

adnan_merter

Full Member level 3
Joined
Jan 23, 2008
Messages
160
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Location
The most beautiful city of the world
Activity points
2,526
hi all,

i need to convert a string array which is read from rs232 to a double value,

i mean the string is "12345.1234" and i need to convert it to 12345.1234

i know the atof() function does this job, but there is no such data type as "double" in CCS C language,

is the float data type ok?
thanks
 

float64 is the 'double' in the CCS PCD compiler (for dsPIC, PIC24), and the word 'double' can be used there, but it is not available in the 8-bit compiler.

In the 8-bit (PCW), float is 32 bits and all floating point functions work with and return this type.
 

Yes, a float is the same as a double apart from it uses half the number of bits to encode your number in, this means that the accuracy and/or range is affected, so instead of being able to store 12345.12345 you might only be able to store with the accuracy of 12345.123 or the range of 123.12345.
If you really want to understand how floating point numbers work then there is an IEEE standard that is the most commonly used representation that will explain all.

Hope this helps.

/Pheetuz
 
Hello!

Just a comment about float numbers: do you really need float numbers?
Usually when using a micro controller, a good thing to do is to avoid float numbers.
In many years of development, I used float only once for an IIR filter, and I used
it mostly because I didn't have time to think about how to do to avoid them.
Be aware that on a MCU, for instance multiplying 2 16-bit numbers is done extremely
quickly (order of magnitude : 20 clocks if you count the moves to registers), and if
you multiply 2 float numbers, it will be awfully slow (order of magnitude: 300 clocks).

Dora.
 

thanks for comment doraemon,

i am receiving some values like "12345.123" how can i convert them into a real numbers in order to use them in some mathematical functions,

if there is any other way, please tell me.

i really need some advice at this point,

thamks
 

Hello!

There are standard functions for that. I'm not sure they are implemented on your processor,
but scanf("%f", &value) should do the job.
If it's not implemented, implement it yourself:
Add the value represented by each character of the string weighted by its position in the string.
12345.123 = ('1' - '0') * 10000 + ('2' - '0') * 1000 + ..... + ('3' - '0') * 0.001

Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top