Fixed point numbers in C

Continuing the theme of interview questions, last week I was asked about fixed point numbers in C.

I am aware that there is a proposal to add this feature to the language, but I've never actually seen it.

Are there any compilers offering this?

(I told the guy that I would write my own routines for the scaling that I needed).

tim

Reply to
tims next home
Loading thread data ...

tims next home schrieb:

Yes, GCC 4.3.0 has them, but as far as I know it has only been implemented for the MIPS architecture so far.

Nils

Reply to
Nils

See

formatting link
for the proposal and
formatting link
for a Dr. Dobbs writeup.

The proposal is weak, in my opinion, since you cannot specify the location of the binary point.

See

formatting link

Sounds good to me.

--
Thad
Reply to
Thad Smith

The binary point is processor defined in the same way that integers are processor defined. My experience using fracts and accums has been that we made a reasonable choice.

Fracts and accums were designed to map on the existing processors that support fixed point math. Our implementation on small embedded systems processors has been 8,16,24 bit fracts and each corresponding accum is one byte longer (16,24,32 bits)

We have support for automotive engine controllers using 18037 and have released 6808 families (68hc08,68S08 and RS08). Updates o the other processors we support will include fixed point support

Regards

-- Walter Banks Byte Craft Limited Tel. (519) 888-6911

formatting link
snipped-for-privacy@bytecraft.com

Reply to
Walter Banks

The few times I have used fixed point, I have optimized the representation, say 6.10 for a 16-bit unsigned value needing to represent a maximum of 48.

IIRC PL/I has a specified binary point. TI Pascal for the TMS9900 (decades ago) had user-specified binary point for fixed point types.

The added types may find some good use.

--
Thad
Reply to
Thad Smith

tims next home schrieb:

Well, when you can do the scaling yourself, fixed-point maths isn't that hard anyways as it all breaks down to integer math and some shifting. IIRC there are some similar implementations out there called "fractional". I do remember that from the Blackfin development board we had at the DSP lab in university, where the processor itself had an additional (?) 1.15-(un-)signed-fractional ALU. Using C we still had to code something like c = a * b ; c >> 15; which the compiler optimized away into the required ASM Opcodes.

HTH, Florian

Reply to
Florian Teply

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.