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.

Datatypes for numbers greater than 8 digits in CCS 4

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
Hello,

I am using MSP430 series mcu and CCS4 IDE.

I have to manipulate data upto 12 digits max. (9999999999.99)
I assumed only float can carry this much sized values since its limit seems to be 3.4 e^38. So, I declared variables as float. Now, even floats can't work for my purpose. The values greater than 8 digits are erroneous (I see them erroneous when I use sprintf function over them).

I have tried with "double" which is 64 bit in CCS4. But, that is not supported by CCS4.

Kindly let me know, how could I declare and manipulate such a high valued variables?
 

I'm not using TI code composer, but a brief view to the compiler specification suggests that it supports signed and unsigned long long (64 bit integer). That's definitely the way to go.

**broken link removed**

There seems to be an application binary interface supporting double (64 bit floating point) as well...
 
Do you really need floating point? Can you use integers with a known decimal position? That's what I end up doing most of the time. Floating point is rarely absolutely essential.

On page 67 of the datasheet linked by FvM, you can see that 64-bit integers (both signed and unsigned) are supported. They will give you plenty of resolution without floating point errors and overhead.

(I know, I've just echoed what FvM said. My Excuse: I've just got back from the gym and my brain is too low on sugar to read properly!)
 
Last edited:

The variables I am using need to be float because they are result of mathematical operations involving float values (like slope, intercept, rate of item etc)

I already referred, the user guide you recommended, but when I actually tested it on IDE, it failed. I dug it out on TI forums and there I got to know that, CCS4 doesnt support 64bit data type. In fact, that support was to launch in late 2012.

So, I am not left with any choice but to use float. :cry:
 

The variables I am using need to be float because they are result of mathematical operations involving float values (like slope, intercept, rate of item etc).
Sounds like a not well considered application design.

It's of course possible to perform all calculations based on integer arithmetic, although less convenient. If the integer accuracy of available libraries doesn't sufice, you can design your own math support.

IMHO the example given in your previous post (totalized flow) seems to suggest an integer quantity by nature. https://www.edaboard.com/threads/264811/
 
Yes Sir, Exactly, Totalised Flow can be an integer value.
But, problem comes if I declare it as int or long as the max value for totalised flow can go to 9999999999 and neither int nor long support this value.
Further, 64 bit double is not supported by CCS4 (even though compiler user guide says so, as I mentioned in above post.)

So, I simply saw that float value limit is 3.4e^38 in the same user guide of compiler and thought that my purpose would be served if I declare totalised flow as float.

Now, there are some variables which are actually floats in my project. They include multiplications with 0.2, 89.72, 199.23 etc. So, my first preference for the variables was float.

I dont have considerable experience with the float variable neither do I used sprintf before.
So, at both the places, now I am struggling. :-?
 

But long long should be available for the present compiler version, isn't it?
 
Last edited:

Short comment, the manual linked in post #2 is in fact the recent MSP430 Optimizing C/C++ Compiler v 4.1 user's guide.
If you have the same version, I would ask if a document can be more misleading? But I'm not using MSP430 - and don't intend to. So it's not actually my problem.
 
Ok...
Even I am struggling because of the misleading information.
I thought it was true and did design and now being screwed up. :cry:

Anyways, I must find out the solution for it now. :idea:
 

The variables I am using need to be float because they are result of mathematical operations involving float values (like slope, intercept, rate of item etc)

Mathematical operations calculating slope, intercept and rate typically yield Rational or Irrational numbers as results, not floating point.

Floating Point is nothing more that a system/specification by which to represent and store such a numerical value/result, one of several possible systems/specifications available to the programmer.

I have to manipulate data upto 12 digits max. (9999999999.99)
I assumed only float can carry this much sized values since its limit seems to be 3.4 e^38. So, I declared variables as float. Now, even floats can't work for my purpose. The values greater than 8 digits are erroneous (I see them erroneous when I use sprintf function over them).

Due to the inherent nature of the IEEE754 Floating Point specification, there are an INFINITE number of rational numbers, not to mention the INFINITE number of irrational numbers, which cannot be represented exactly using the IEEE754 Floating Point specification.

Take for example the common rational number 1/10 or 0.1, which CANNOT be represented exactly using the IEEE754 Floating Point specification. If fact the resulting binary floating point representation becomes the infinitely repeating binary decimal

.0001100110011100110011....

which of course is then rounded down to some approximation when it is stored.

Unfortunately, these facts will result in some level of error, often significant, regardless of the number of bits using in the Floating Point representation. In other words, I'm not sure the entire situation will significantly improve with 64-bit Floating Point system.

Some additional gotchas to be aware of when using the IEEE754 Floating Point specification:

Every decimal integer can be exactly represented by a binary integer; however, this is not true for fractional numbers. In fact, every number that is irrational in base 10 will also be irrational in any system with a base smaller than 10.

For binary, in particular, only fractional numbers that can be represented in the form p/q, where q is an integer power of 2, can be expressed exactly, with a finite number of bits.

Even common decimal fractions, such as decimal 0.0001, cannot be represented exactly in binary. (0.0001 is a repeating binary fraction with a period of 104 bits!)

If high levels of precision are required, you may want to consider using a Fixed Point system, in fact a 32-bit Fixed Point system can offer more precision then a 32-bit Floating Point system. One of the reasons why a Fixed Point system is used in many DSPs, rather than Floating Point system.

There are open source Fixed Point libraries available, TI may offer Fixed Point routines in their compiler libraries, and it is not too difficult to write your own, although some Assembly maybe required. :lol: :roll:

Introduction to Fixed Point Representation

**broken link removed**

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top