<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Unnecessary floating point support?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/20827/unnecessary-floating-point-support</link><description> 
Hi, 

 
My problem is that I have integer constants coded as
 compile-time constant floating equations to avoid having to
use the floating point library... let me explain... 

 
Take some code that does not use floating point operations
- say: 

 
void</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/138511?ContentTypeID=1</link><pubDate>Wed, 01 Aug 2007 20:50:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f4a94516-8fcf-4803-97b2-f599e2f4cc27</guid><dc:creator>Robert McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry I believe I got my &amp;quot;rounding&amp;quot; (or truncating) wrong. But
these numbers do come out to be EXACT integers. There should be no
need to use floating point.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/135083?ContentTypeID=1</link><pubDate>Wed, 01 Aug 2007 15:59:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:32cbba18-36de-46f4-bc45-72ba887f7f1d</guid><dc:creator>Robert McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;

&lt;pre&gt;
&lt;i&gt;#define DAC_const       (15.0/255)
#define VPP_5V          (BYTE)((5.0/DAC_const)+0.5)
#define VPP_12V         (BYTE)((12.0/DAC_const)+0.5)
#define VPP_OFF         (BYTE)((0.0/DAC_const)+0.5
&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;Because of this limitation, the code has to be
written:&lt;br /&gt;&lt;/i&gt;&lt;/p&gt;

&lt;pre&gt;
&lt;i&gt;#define VPP_5V                     (BYTE)(85U)
#define VPP_12V                 (BYTE)(204U)
#define VPP_OFF                 (BYTE)(0U)
&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
which is not as good.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
If you changed the definitions to the following they would be the
same as the floating point versions&lt;/p&gt;

&lt;pre&gt;
#define VPP_5V (BYTE)(86U) //(BYTE)((5.0/DAC_const)+0.5) evaluates to 86 not 85
#define VPP_12V (BYTE) (205U)
#define VPP_OFF (BYTE) (1U)

#define ONE_OVER_DAC_CONSTANT (17U)

// Because 1 / DAC_const is an exact integer (17) , you could do 5 * 17 and just add 1 because you are rounding up.


&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/123972?ContentTypeID=1</link><pubDate>Wed, 01 Aug 2007 14:32:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d7005fb4-ada4-4735-9154-87cffbb2b10c</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;but the resulting code would still require a word or two of
explanation&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Well, if the answer was completely obvious, it wouldn&amp;#39;t have been
much of an &lt;b&gt;exercise&lt;/b&gt; to be left to the reader, now would it?
;-)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/135082?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 20:10:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:eaf9b37b-2c38-4e69-8843-b835d9597af3</guid><dc:creator>Robert McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry if your target includes floating point libraries behind the
scenes. If I do not use floating point calulations at run time, no
support is added in my builds (and therefore also not initialized).
(My target is STR71X). It would be interesting to know why it is
including floating point libraries AND initializing them if you are
not using them. Maybe your map file would give a hint as to why they
were being included. Maybe not.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/123983?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 16:15:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4e189b18-a95f-4030-9836-95fa7817bfe0</guid><dc:creator>Jason Watton</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;... just remove the &amp;quot;--fpu=none&amp;quot; statement.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Interesting... without this, I get inclusion of the libraries and
the FP library is initialised.&lt;/p&gt;

&lt;p&gt;
Thanks for the suggestions, guys - I will try &lt;b&gt;both&lt;/b&gt;.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/123974?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 16:07:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4bb387f8-ce73-424f-8f4f-a7af80f2bc90</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
No much shame, since the &amp;quot;workaround&amp;quot; is trivial - as long as the
compiler have the numeric range.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/113074?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 15:54:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ce05a67a-b2a6-47cd-b0da-2382aed1daea</guid><dc:creator>Jason Watton</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I&amp;#39;ll leave the addition of the 0.5 term as an exercise.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Shame - you fell short of having to encode 0.5 as a fraction with
a denominator of 15... &lt;i&gt;I know,&lt;/i&gt; and I know &lt;i&gt;you&lt;/i&gt; know, how
to fix this, but the resulting code would still require a word or two
of explanation (denominator of &amp;quot;15*2&amp;quot;?) - hence the word &amp;quot;shame&amp;quot; [as
in pity]...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/113073?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 09:37:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4085eda6-4d8f-44c0-84ab-080e9667a363</guid><dc:creator>Robert McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
I like Hans-Bernhard&amp;#39;s suggestion, but also you could just remove
the &amp;quot;--fpu=none&amp;quot; statement.&lt;/p&gt;

&lt;p&gt;
All the statement does is cause an error when you try and use a
floating-point type. It does not actually make your code any smaller.
(At least it does not for mine). It is fully a &amp;quot;compile time&amp;quot; option
and not a &amp;quot;run time&amp;quot; or &amp;quot;Code Generation&amp;quot; option.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/99472?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2007 02:37:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7a312761-e283-4770-82c1-49c12b0d7c53</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Because of this limitation, the code has to be written:&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That conclusion is premature.&lt;/p&gt;

&lt;p&gt;
The standard practice for this kind of job is to slightly reorder
the equation:&lt;/p&gt;

&lt;pre&gt;
#define DAC_numerator   15
#define DAC_denominator 255
#define VPP_5V          (BYTE)((5 * DAC_denominator) / /DAC_numerator)
&lt;/pre&gt;

&lt;p&gt;
I&amp;#39;ll leave the addition of the 0.5 term as an exercise.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/75315?ContentTypeID=1</link><pubDate>Mon, 30 Jul 2007 16:02:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c9239f14-96c3-4b86-b41b-c2ebf92da8b0</guid><dc:creator>Jason Watton</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Reinhard,&lt;/p&gt;

&lt;p&gt;
This is a pity - this decreases the readability of the source
code. An explanation...&lt;/p&gt;

&lt;p&gt;
The floating point (constant) calculations are needed in the
following lines which translate a voltage to a byte value driving a
D-to-A:&lt;/p&gt;

&lt;pre&gt;
/*
// Vpp is driven from a +15V feed, divided by an 8-bit value.
// This gives a multiplier of +15V/255 of the programmed value.
// The byte value sent to the encoder is the rounded up version of
// the voltage divided by the DAC const (15/255=0.0588235).
*/
#define DAC_const       (15.0/255)
#define VPP_5V          (BYTE)((5.0/DAC_const)+0.5)
#define VPP_12V         (BYTE)((12.0/DAC_const)+0.5)
#define VPP_OFF         (BYTE)((0.0/DAC_const)+0.5
&lt;/pre&gt;

&lt;p&gt;
Because of this limitation, the code has to be written:&lt;/p&gt;

&lt;pre&gt;
#define VPP_5V                     (BYTE)(85U)
#define VPP_12V                 (BYTE)(204U)
#define VPP_OFF                 (BYTE)(0U)
&lt;/pre&gt;

&lt;p&gt;
which is not as good.&lt;/p&gt;

&lt;p&gt;
It&amp;#39;s a pity - thanks for the explanation, though.&lt;/p&gt;

&lt;p&gt;
Jason.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unnecessary floating point support?</title><link>https://community.arm.com/thread/50980?ContentTypeID=1</link><pubDate>Mon, 30 Jul 2007 09:51:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7c6e426e-ff5b-43f6-b082-5e89d4e2458b</guid><dc:creator>Reinhard Keil</dc:creator><description>&lt;p&gt;&lt;p&gt;
With --fpu=none you basically disable all floating point support.
Even when your code compiles into a simple constant, the compiler
traps floating point operations in such cases.&lt;/p&gt;

&lt;p&gt;
So to avoid this type of errors just write:&lt;/p&gt;

&lt;pre&gt;
unsigned int j = 1*3;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>