What exactly is meant by fixed point? How do you ensure fixed point calculations in programs?Originally Posted by filker0
Thanks
Eddie
What exactly is meant by fixed point? How do you ensure fixed point calculations in programs?Originally Posted by filker0
Thanks
Eddie
Homepage: http://www.eddie-meyer.com
My C Programming Page: http://www.eddie-meyer.com/docs/prog...c/c-index.html
Oh, yeah, well when you send me an email that says, and I quote:Originally Posted by filker0One has to wonder who's taking what personal. Hmm? Especially considering it came out of the blue, because I apparently commented on some post of yours. And that apprently upset you. I guess no one is allowed to point out your mistakes. Seems like you're continually overcompensating. But we won't go there.Though I'm willing to bet that I'm more experienced with C than you are.
So, yeah. Sorry about your penis.Originally Posted by filker0
I didn't take issue with you. I said it was an accurate statement. It is in fact accurate. Doubles are designed to be bigger than floats. That's fact. That was my point that for some reason you disagreed with it. I guess ... well, see above.Originally Posted by filker0
edit in blue
Quzah.
Last edited by quzah; 12-06-2005 at 12:56 PM.
Hope is the first step on the road to disappointment.
Fixed point is where you have a representation of non-integer values that has a fixed precision. Other than the trivial case of integer math (which is, in a sense, fixed point, since there is no fractional part), fixed point is not directly supported by the standard C language. You can do fixed point many ways, and there are a number of libraries out there that do it different ways. Depending on the range you require (maximum/minimum values) and precision desired, different strategies are used.Originally Posted by emeyer
In some cases, a fixed point value is represented by a structure containing a whole and fractional part. In these cases, all arithmetic on fixed point values is done by passing pointers to fixed point objects (structs) (or the structs themselves) to functions that have been defined by the fixed point library you're using -- these libraries enforce specific rounding/truncation rules on division and multiplication. (In C++, I've seen this done with classes and operator overloading, as in this link, but we're talking about C here.)
Another technique used for fixed point is BCD (Binary Coded Decimal), which predates digital computers. In this representation, four bits are used for each decimal digit. To use this in C, you need a BCD library.
Another common technique used for fixed point is to use an integer type, such as a long or a long long (64 bits), and have an implied decimal point. Here, you can use the built-in arithmetic in C, but multiplication and division require some fix-up afterwards to keep the decimal point in the right place. There are some issues about how wide the result of a multiply is (eg: to avoid overflow, multiplying two 32 bit fixed point numbers requires 64 bits for the result, then adjust the value to move the decimal point to the right place, then check for result overflow which keeps the fixed-point result from fitting in your normal fixed point representation, and if there is no overflow, just take the lower 32 bits -- what you do with overflow is application or library specific) and things of that sort, and your range will be somewhat limited. An example of this strategy can be found at this Stanford university web page.
Fixed point is sometimes used for high performance signal processing and graphics engines, since their coordinate space is limited and fixed, "enough precision" is well defined, and floating point operations are expensive; eg: this example from Intel.
Some special and general purpose processors support native fixed point formats. C compilers for those processors sometimes include extensions to allow C programs to declare and use fixed point variables, but these are non-portable.
Some programming languages do support built-in fixed point representations, such as PL/1 and Cobol.
A very good overview and source of fixed-point (and arbitrary precision) information and libraries is at this IBM site.
Last edited by filker0; 12-06-2005 at 03:05 PM. Reason: Add a very good reference to the topic
Insert obnoxious but pithy remark here
This isn't right, surely? Even if it had been malloc'd (which it hadn't), you can't do it this way surely?Code:last_name = "Meyer";
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
Surely you can. last_name is a pointer and you are assigning it the address of the string constant "Meyer". All is kosher as long as you don't try to change the string.
If you say so. I know you can initialise string that way, but I was always taught to use strcpy. And I also thought the compiler wouldn't reserve any chars for a string simply by declaring a char*.
Also, what's the pointer pointing to? It hasn't been malloc'd.
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
>but I was always taught to use strcpy
That's if you want a copy of the string.
>And I also thought the compiler wouldn't reserve any chars for a string simply by declaring a char*.
It reserves enough memory for a pointer, and then you can point it wherever you want, including to a string literal.
>Also, what's the pointer pointing to? It hasn't been malloc'd.
It's pointing to a string literal. There's no need to allocate memory for an existing object.
My best code is written with the delete key.
> last_name = "Meyer";
It's like
const char anon[] = "Meyer"; last_name = anon;
Without all the annoyance of having to make up non-existent names for things yourself.
Storage is reserved and initialised by the compiler, and then assigns the pointer to the start of that storage.