Suggestion: Fixed or half-precision

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Suggestion: Fixed or half-precision

Post by SHughes_Fusion » Thu May 08, 2014 1:34 pm

While it is very handy that Swordfish supports Floats - some other compilers don't, or make you buy a higher price version - I often find myself thinking that I don't actually need the accuracy a 32-bit float offers. You can see from the increase in program size how much code using floats adds, and I would suspect there is also a big performance penalty.

Therefore, as a suggestion, would it be viable to implement either a fixed point or half-precision floating point type?

Many of the embedded systems I've created either need or are made much easier by using floats, but often I only need 1 or 2 decimal places of accuracy. For example, at the moment I'm logging pressure and temperature. I do need to resolve to at least tenths but all readings are under 250 so just to get slightly more accuracy I'm stepping up from a 8-bit data type to a 32-bit type. If there was an intermediate type it would help a lot.

Now I know there is a work-around for this - use a Word and multiply all values by 10 - but this isn't easy to document, isn't very readable to anyone who needs to modify my code at a later date and is very easy to forget to implement in all places it is needed, plus can't be used in normal expressions.

Would any other users find such a type useful and would David consider implementing it if there is enough demand?

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Suggestion: Fixed or half-precision

Post by David Barker » Thu May 08, 2014 3:39 pm

Introducing a new type into the compiler is a huge undertaking in terms of both coding and testing. I think it highly unlikely that I would do this. However, I do appreciate you input.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Suggestion: Fixed or half-precision

Post by SHughes_Fusion » Wed May 14, 2014 8:45 am

Thanks, David. I think the fact no-one else has commented on this topic does suggest there is limited interest anyway so I can see it isn't viable for you to implement it for a very limited demand.

Out of interest, I tried changing the three parameters I used floats for to use words with their value multiplied by 10 so I could still resolve to tenths. Despite having to add extra code to separate the decimal portion in a few places I saved over 2k bytes of program memory and 125 bytes of RAM so for anyone else who has a similar concern I can recommend trying this sort of solution rather than relying on floats.

Post Reply