Skip to content

Commit 2dad7ee

Browse files
committed
[LangRef] Document integer hexadecimal constants
It's possible to write an integer constant in hexadecimal, but you need to prefix it with u or s. I couldn't find this mentioned anywhere in the LangRef, so this adds a small note about it. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D158288
1 parent 23f08af commit 2dad7ee

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llvm/docs/LangRef.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,9 +4093,17 @@ Simple Constants
40934093
The two strings '``true``' and '``false``' are both valid constants
40944094
of the ``i1`` type.
40954095
**Integer constants**
4096-
Standard integers (such as '4') are constants of the
4097-
:ref:`integer <t_integer>` type. Negative numbers may be used with
4098-
integer types.
4096+
Standard integers (such as '4') are constants of the :ref:`integer
4097+
<t_integer>` type. They can be either decimal or
4098+
hexadecimal. Decimal integers can be prefixed with - to represent
4099+
negative integers, e.g. '``-1234``'. Hexadecimal integers must be
4100+
prefixed with either u or s to indicate whether they are unsigned
4101+
or signed respectively. e.g '``u0x8000``' gives 32768, whilst
4102+
'``s0x8000``' gives -32768.
4103+
4104+
Note that hexadecimal integers are sign extended from the number
4105+
of active bits, i.e. the bit width minus the number of leading
4106+
zeros. So '``s0x0001``' of type '``i16``' will be -1, not 1.
40994107
**Floating-point constants**
41004108
Floating-point constants use standard decimal notation (e.g.
41014109
123.421), exponential notation (e.g. 1.23421e+2), or a more precise

0 commit comments

Comments
 (0)