You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
10KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Fixed-Point (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Fixed-Point (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Fixed-Point (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Fixed_002dPoint"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Fixed_002dPoint-Types"></a>
  68. <h3 class="section">6.16 Fixed-Point Types</h3>
  69. <a name="index-fixed_002dpoint-types"></a>
  70. <a name="index-_005fFract-data-type"></a>
  71. <a name="index-_005fAccum-data-type"></a>
  72. <a name="index-_005fSat-data-type"></a>
  73. <a name="index-hr-fixed_002dsuffix"></a>
  74. <a name="index-r-fixed_002dsuffix"></a>
  75. <a name="index-lr-fixed_002dsuffix"></a>
  76. <a name="index-llr-fixed_002dsuffix"></a>
  77. <a name="index-uhr-fixed_002dsuffix"></a>
  78. <a name="index-ur-fixed_002dsuffix"></a>
  79. <a name="index-ulr-fixed_002dsuffix"></a>
  80. <a name="index-ullr-fixed_002dsuffix"></a>
  81. <a name="index-hk-fixed_002dsuffix"></a>
  82. <a name="index-k-fixed_002dsuffix"></a>
  83. <a name="index-lk-fixed_002dsuffix"></a>
  84. <a name="index-llk-fixed_002dsuffix"></a>
  85. <a name="index-uhk-fixed_002dsuffix"></a>
  86. <a name="index-uk-fixed_002dsuffix"></a>
  87. <a name="index-ulk-fixed_002dsuffix"></a>
  88. <a name="index-ullk-fixed_002dsuffix"></a>
  89. <a name="index-HR-fixed_002dsuffix"></a>
  90. <a name="index-R-fixed_002dsuffix"></a>
  91. <a name="index-LR-fixed_002dsuffix"></a>
  92. <a name="index-LLR-fixed_002dsuffix"></a>
  93. <a name="index-UHR-fixed_002dsuffix"></a>
  94. <a name="index-UR-fixed_002dsuffix"></a>
  95. <a name="index-ULR-fixed_002dsuffix"></a>
  96. <a name="index-ULLR-fixed_002dsuffix"></a>
  97. <a name="index-HK-fixed_002dsuffix"></a>
  98. <a name="index-K-fixed_002dsuffix"></a>
  99. <a name="index-LK-fixed_002dsuffix"></a>
  100. <a name="index-LLK-fixed_002dsuffix"></a>
  101. <a name="index-UHK-fixed_002dsuffix"></a>
  102. <a name="index-UK-fixed_002dsuffix"></a>
  103. <a name="index-ULK-fixed_002dsuffix"></a>
  104. <a name="index-ULLK-fixed_002dsuffix"></a>
  105. <p>As an extension, GNU C supports fixed-point types as
  106. defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
  107. types in GCC will evolve as the draft technical report changes.
  108. Calling conventions for any target might also change. Not all targets
  109. support fixed-point types.
  110. </p>
  111. <p>The fixed-point types are
  112. <code>short _Fract</code>,
  113. <code>_Fract</code>,
  114. <code>long _Fract</code>,
  115. <code>long long _Fract</code>,
  116. <code>unsigned short _Fract</code>,
  117. <code>unsigned _Fract</code>,
  118. <code>unsigned long _Fract</code>,
  119. <code>unsigned long long _Fract</code>,
  120. <code>_Sat short _Fract</code>,
  121. <code>_Sat _Fract</code>,
  122. <code>_Sat long _Fract</code>,
  123. <code>_Sat long long _Fract</code>,
  124. <code>_Sat unsigned short _Fract</code>,
  125. <code>_Sat unsigned _Fract</code>,
  126. <code>_Sat unsigned long _Fract</code>,
  127. <code>_Sat unsigned long long _Fract</code>,
  128. <code>short _Accum</code>,
  129. <code>_Accum</code>,
  130. <code>long _Accum</code>,
  131. <code>long long _Accum</code>,
  132. <code>unsigned short _Accum</code>,
  133. <code>unsigned _Accum</code>,
  134. <code>unsigned long _Accum</code>,
  135. <code>unsigned long long _Accum</code>,
  136. <code>_Sat short _Accum</code>,
  137. <code>_Sat _Accum</code>,
  138. <code>_Sat long _Accum</code>,
  139. <code>_Sat long long _Accum</code>,
  140. <code>_Sat unsigned short _Accum</code>,
  141. <code>_Sat unsigned _Accum</code>,
  142. <code>_Sat unsigned long _Accum</code>,
  143. <code>_Sat unsigned long long _Accum</code>.
  144. </p>
  145. <p>Fixed-point data values contain fractional and optional integral parts.
  146. The format of fixed-point data varies and depends on the target machine.
  147. </p>
  148. <p>Support for fixed-point types includes:
  149. </p><ul>
  150. <li> prefix and postfix increment and decrement operators (<code>++</code>, <code>--</code>)
  151. </li><li> unary arithmetic operators (<code>+</code>, <code>-</code>, <code>!</code>)
  152. </li><li> binary arithmetic operators (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>)
  153. </li><li> binary shift operators (<code>&lt;&lt;</code>, <code>&gt;&gt;</code>)
  154. </li><li> relational operators (<code>&lt;</code>, <code>&lt;=</code>, <code>&gt;=</code>, <code>&gt;</code>)
  155. </li><li> equality operators (<code>==</code>, <code>!=</code>)
  156. </li><li> assignment operators (<code>+=</code>, <code>-=</code>, <code>*=</code>, <code>/=</code>,
  157. <code>&lt;&lt;=</code>, <code>&gt;&gt;=</code>)
  158. </li><li> conversions to and from integer, floating-point, or fixed-point types
  159. </li></ul>
  160. <p>Use a suffix in a fixed-point literal constant:
  161. </p><ul>
  162. <li> &lsquo;<samp>hr</samp>&rsquo; or &lsquo;<samp>HR</samp>&rsquo; for <code>short _Fract</code> and
  163. <code>_Sat short _Fract</code>
  164. </li><li> &lsquo;<samp>r</samp>&rsquo; or &lsquo;<samp>R</samp>&rsquo; for <code>_Fract</code> and <code>_Sat _Fract</code>
  165. </li><li> &lsquo;<samp>lr</samp>&rsquo; or &lsquo;<samp>LR</samp>&rsquo; for <code>long _Fract</code> and
  166. <code>_Sat long _Fract</code>
  167. </li><li> &lsquo;<samp>llr</samp>&rsquo; or &lsquo;<samp>LLR</samp>&rsquo; for <code>long long _Fract</code> and
  168. <code>_Sat long long _Fract</code>
  169. </li><li> &lsquo;<samp>uhr</samp>&rsquo; or &lsquo;<samp>UHR</samp>&rsquo; for <code>unsigned short _Fract</code> and
  170. <code>_Sat unsigned short _Fract</code>
  171. </li><li> &lsquo;<samp>ur</samp>&rsquo; or &lsquo;<samp>UR</samp>&rsquo; for <code>unsigned _Fract</code> and
  172. <code>_Sat unsigned _Fract</code>
  173. </li><li> &lsquo;<samp>ulr</samp>&rsquo; or &lsquo;<samp>ULR</samp>&rsquo; for <code>unsigned long _Fract</code> and
  174. <code>_Sat unsigned long _Fract</code>
  175. </li><li> &lsquo;<samp>ullr</samp>&rsquo; or &lsquo;<samp>ULLR</samp>&rsquo; for <code>unsigned long long _Fract</code>
  176. and <code>_Sat unsigned long long _Fract</code>
  177. </li><li> &lsquo;<samp>hk</samp>&rsquo; or &lsquo;<samp>HK</samp>&rsquo; for <code>short _Accum</code> and
  178. <code>_Sat short _Accum</code>
  179. </li><li> &lsquo;<samp>k</samp>&rsquo; or &lsquo;<samp>K</samp>&rsquo; for <code>_Accum</code> and <code>_Sat _Accum</code>
  180. </li><li> &lsquo;<samp>lk</samp>&rsquo; or &lsquo;<samp>LK</samp>&rsquo; for <code>long _Accum</code> and
  181. <code>_Sat long _Accum</code>
  182. </li><li> &lsquo;<samp>llk</samp>&rsquo; or &lsquo;<samp>LLK</samp>&rsquo; for <code>long long _Accum</code> and
  183. <code>_Sat long long _Accum</code>
  184. </li><li> &lsquo;<samp>uhk</samp>&rsquo; or &lsquo;<samp>UHK</samp>&rsquo; for <code>unsigned short _Accum</code> and
  185. <code>_Sat unsigned short _Accum</code>
  186. </li><li> &lsquo;<samp>uk</samp>&rsquo; or &lsquo;<samp>UK</samp>&rsquo; for <code>unsigned _Accum</code> and
  187. <code>_Sat unsigned _Accum</code>
  188. </li><li> &lsquo;<samp>ulk</samp>&rsquo; or &lsquo;<samp>ULK</samp>&rsquo; for <code>unsigned long _Accum</code> and
  189. <code>_Sat unsigned long _Accum</code>
  190. </li><li> &lsquo;<samp>ullk</samp>&rsquo; or &lsquo;<samp>ULLK</samp>&rsquo; for <code>unsigned long long _Accum</code>
  191. and <code>_Sat unsigned long long _Accum</code>
  192. </li></ul>
  193. <p>GCC support of fixed-point types as specified by the draft technical report
  194. is incomplete:
  195. </p>
  196. <ul>
  197. <li> Pragmas to control overflow and rounding behaviors are not implemented.
  198. </li></ul>
  199. <p>Fixed-point types are supported by the DWARF debug information format.
  200. </p>
  201. <hr>
  202. <div class="header">
  203. <p>
  204. 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>
  205. </div>
  206. </body>
  207. </html>