Fixed_002dPoint.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Fixed-Point</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Fixed-Point">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Fixed-Point">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C-Extensions.html#C-Extensions" rel="up" title="C Extensions">
  30. <link href="Named-Address-Spaces.html#Named-Address-Spaces" rel="next" title="Named Address Spaces">
  31. <link href="Hex-Floats.html#Hex-Floats" rel="prev" title="Hex Floats">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Fixed_002dPoint"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Named-Address-Spaces.html#Named-Address-Spaces" accesskey="n" rel="next">Named Address Spaces</a>, Previous: <a href="Hex-Floats.html#Hex-Floats" accesskey="p" rel="prev">Hex Floats</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Fixed_002dPoint-Types"></a>
  69. <h3 class="section">6.15 Fixed-Point Types</h3>
  70. <a name="index-fixed_002dpoint-types"></a>
  71. <a name="index-_005fFract-data-type"></a>
  72. <a name="index-_005fAccum-data-type"></a>
  73. <a name="index-_005fSat-data-type"></a>
  74. <a name="index-hr-fixed_002dsuffix"></a>
  75. <a name="index-r-fixed_002dsuffix"></a>
  76. <a name="index-lr-fixed_002dsuffix"></a>
  77. <a name="index-llr-fixed_002dsuffix"></a>
  78. <a name="index-uhr-fixed_002dsuffix"></a>
  79. <a name="index-ur-fixed_002dsuffix"></a>
  80. <a name="index-ulr-fixed_002dsuffix"></a>
  81. <a name="index-ullr-fixed_002dsuffix"></a>
  82. <a name="index-hk-fixed_002dsuffix"></a>
  83. <a name="index-k-fixed_002dsuffix"></a>
  84. <a name="index-lk-fixed_002dsuffix"></a>
  85. <a name="index-llk-fixed_002dsuffix"></a>
  86. <a name="index-uhk-fixed_002dsuffix"></a>
  87. <a name="index-uk-fixed_002dsuffix"></a>
  88. <a name="index-ulk-fixed_002dsuffix"></a>
  89. <a name="index-ullk-fixed_002dsuffix"></a>
  90. <a name="index-HR-fixed_002dsuffix"></a>
  91. <a name="index-R-fixed_002dsuffix"></a>
  92. <a name="index-LR-fixed_002dsuffix"></a>
  93. <a name="index-LLR-fixed_002dsuffix"></a>
  94. <a name="index-UHR-fixed_002dsuffix"></a>
  95. <a name="index-UR-fixed_002dsuffix"></a>
  96. <a name="index-ULR-fixed_002dsuffix"></a>
  97. <a name="index-ULLR-fixed_002dsuffix"></a>
  98. <a name="index-HK-fixed_002dsuffix"></a>
  99. <a name="index-K-fixed_002dsuffix"></a>
  100. <a name="index-LK-fixed_002dsuffix"></a>
  101. <a name="index-LLK-fixed_002dsuffix"></a>
  102. <a name="index-UHK-fixed_002dsuffix"></a>
  103. <a name="index-UK-fixed_002dsuffix"></a>
  104. <a name="index-ULK-fixed_002dsuffix"></a>
  105. <a name="index-ULLK-fixed_002dsuffix"></a>
  106. <p>As an extension, GNU C supports fixed-point types as
  107. defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
  108. types in GCC will evolve as the draft technical report changes.
  109. Calling conventions for any target might also change. Not all targets
  110. support fixed-point types.
  111. </p>
  112. <p>The fixed-point types are
  113. <code>short _Fract</code>,
  114. <code>_Fract</code>,
  115. <code>long _Fract</code>,
  116. <code>long long _Fract</code>,
  117. <code>unsigned short _Fract</code>,
  118. <code>unsigned _Fract</code>,
  119. <code>unsigned long _Fract</code>,
  120. <code>unsigned long long _Fract</code>,
  121. <code>_Sat short _Fract</code>,
  122. <code>_Sat _Fract</code>,
  123. <code>_Sat long _Fract</code>,
  124. <code>_Sat long long _Fract</code>,
  125. <code>_Sat unsigned short _Fract</code>,
  126. <code>_Sat unsigned _Fract</code>,
  127. <code>_Sat unsigned long _Fract</code>,
  128. <code>_Sat unsigned long long _Fract</code>,
  129. <code>short _Accum</code>,
  130. <code>_Accum</code>,
  131. <code>long _Accum</code>,
  132. <code>long long _Accum</code>,
  133. <code>unsigned short _Accum</code>,
  134. <code>unsigned _Accum</code>,
  135. <code>unsigned long _Accum</code>,
  136. <code>unsigned long long _Accum</code>,
  137. <code>_Sat short _Accum</code>,
  138. <code>_Sat _Accum</code>,
  139. <code>_Sat long _Accum</code>,
  140. <code>_Sat long long _Accum</code>,
  141. <code>_Sat unsigned short _Accum</code>,
  142. <code>_Sat unsigned _Accum</code>,
  143. <code>_Sat unsigned long _Accum</code>,
  144. <code>_Sat unsigned long long _Accum</code>.
  145. </p>
  146. <p>Fixed-point data values contain fractional and optional integral parts.
  147. The format of fixed-point data varies and depends on the target machine.
  148. </p>
  149. <p>Support for fixed-point types includes:
  150. </p><ul>
  151. <li> prefix and postfix increment and decrement operators (<code>++</code>, <code>--</code>)
  152. </li><li> unary arithmetic operators (<code>+</code>, <code>-</code>, <code>!</code>)
  153. </li><li> binary arithmetic operators (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>)
  154. </li><li> binary shift operators (<code>&lt;&lt;</code>, <code>&gt;&gt;</code>)
  155. </li><li> relational operators (<code>&lt;</code>, <code>&lt;=</code>, <code>&gt;=</code>, <code>&gt;</code>)
  156. </li><li> equality operators (<code>==</code>, <code>!=</code>)
  157. </li><li> assignment operators (<code>+=</code>, <code>-=</code>, <code>*=</code>, <code>/=</code>,
  158. <code>&lt;&lt;=</code>, <code>&gt;&gt;=</code>)
  159. </li><li> conversions to and from integer, floating-point, or fixed-point types
  160. </li></ul>
  161. <p>Use a suffix in a fixed-point literal constant:
  162. </p><ul>
  163. <li> &lsquo;<samp>hr</samp>&rsquo; or &lsquo;<samp>HR</samp>&rsquo; for <code>short _Fract</code> and
  164. <code>_Sat short _Fract</code>
  165. </li><li> &lsquo;<samp>r</samp>&rsquo; or &lsquo;<samp>R</samp>&rsquo; for <code>_Fract</code> and <code>_Sat _Fract</code>
  166. </li><li> &lsquo;<samp>lr</samp>&rsquo; or &lsquo;<samp>LR</samp>&rsquo; for <code>long _Fract</code> and
  167. <code>_Sat long _Fract</code>
  168. </li><li> &lsquo;<samp>llr</samp>&rsquo; or &lsquo;<samp>LLR</samp>&rsquo; for <code>long long _Fract</code> and
  169. <code>_Sat long long _Fract</code>
  170. </li><li> &lsquo;<samp>uhr</samp>&rsquo; or &lsquo;<samp>UHR</samp>&rsquo; for <code>unsigned short _Fract</code> and
  171. <code>_Sat unsigned short _Fract</code>
  172. </li><li> &lsquo;<samp>ur</samp>&rsquo; or &lsquo;<samp>UR</samp>&rsquo; for <code>unsigned _Fract</code> and
  173. <code>_Sat unsigned _Fract</code>
  174. </li><li> &lsquo;<samp>ulr</samp>&rsquo; or &lsquo;<samp>ULR</samp>&rsquo; for <code>unsigned long _Fract</code> and
  175. <code>_Sat unsigned long _Fract</code>
  176. </li><li> &lsquo;<samp>ullr</samp>&rsquo; or &lsquo;<samp>ULLR</samp>&rsquo; for <code>unsigned long long _Fract</code>
  177. and <code>_Sat unsigned long long _Fract</code>
  178. </li><li> &lsquo;<samp>hk</samp>&rsquo; or &lsquo;<samp>HK</samp>&rsquo; for <code>short _Accum</code> and
  179. <code>_Sat short _Accum</code>
  180. </li><li> &lsquo;<samp>k</samp>&rsquo; or &lsquo;<samp>K</samp>&rsquo; for <code>_Accum</code> and <code>_Sat _Accum</code>
  181. </li><li> &lsquo;<samp>lk</samp>&rsquo; or &lsquo;<samp>LK</samp>&rsquo; for <code>long _Accum</code> and
  182. <code>_Sat long _Accum</code>
  183. </li><li> &lsquo;<samp>llk</samp>&rsquo; or &lsquo;<samp>LLK</samp>&rsquo; for <code>long long _Accum</code> and
  184. <code>_Sat long long _Accum</code>
  185. </li><li> &lsquo;<samp>uhk</samp>&rsquo; or &lsquo;<samp>UHK</samp>&rsquo; for <code>unsigned short _Accum</code> and
  186. <code>_Sat unsigned short _Accum</code>
  187. </li><li> &lsquo;<samp>uk</samp>&rsquo; or &lsquo;<samp>UK</samp>&rsquo; for <code>unsigned _Accum</code> and
  188. <code>_Sat unsigned _Accum</code>
  189. </li><li> &lsquo;<samp>ulk</samp>&rsquo; or &lsquo;<samp>ULK</samp>&rsquo; for <code>unsigned long _Accum</code> and
  190. <code>_Sat unsigned long _Accum</code>
  191. </li><li> &lsquo;<samp>ullk</samp>&rsquo; or &lsquo;<samp>ULLK</samp>&rsquo; for <code>unsigned long long _Accum</code>
  192. and <code>_Sat unsigned long long _Accum</code>
  193. </li></ul>
  194. <p>GCC support of fixed-point types as specified by the draft technical report
  195. is incomplete:
  196. </p>
  197. <ul>
  198. <li> Pragmas to control overflow and rounding behaviors are not implemented.
  199. </li></ul>
  200. <p>Fixed-point types are supported by the DWARF debug information format.
  201. </p>
  202. <hr>
  203. <div class="header">
  204. <p>
  205. Next: <a href="Named-Address-Spaces.html#Named-Address-Spaces" accesskey="n" rel="next">Named Address Spaces</a>, Previous: <a href="Hex-Floats.html#Hex-Floats" accesskey="p" rel="prev">Hex Floats</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  206. </div>
  207. </body>
  208. </html>