Skip to content

Commit b7d5b91

Browse files
committed
Start to document number literals
1 parent 9fd2155 commit b7d5b91

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

lib/Language/syntax.pod

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,61 @@ String literals are surrounded by quotes:
212212
213213
See L<quoting|/language/quoting> for many more options.
214214
215-
=begin comment
216-
217215
=head3 Number literals
218216
219-
TODO
217+
Number literals are generally specified in base ten, unless a prefix like
218+
C<0x> (heB<x>ademcimal, base 16), C<0o> (B<o>ctal, base 8) or C<0b>
219+
(B<b>inary, base 2) or an explicit base in adverbial notation like
220+
C<< :16<A0> >> specifies it otherwise. Unlike other programming languages,
221+
leading zeros do I<not> indicate base 8; instea a compile-time warning is
222+
issued
223+
224+
In all literal formats, you can use underscores to group digits;
225+
they don't carry any semantic; the following literals all evaluate to the same
226+
number:
227+
228+
1000000
229+
1_000_000
230+
10_0000
231+
10_00_00
232+
233+
=head4 L<Int|/type/Int> literals
234+
235+
-2
236+
12345
237+
0xBEEF # base 16
238+
0o755 # base 8
239+
240+
=comment TODO adverbial bases with :20<...>
241+
242+
=head4 L<Rat|/type/Rat> literals
243+
244+
1.0
245+
3.14159
246+
-2.5
247+
248+
=comment TODO adverbial bases with :20<...>
249+
250+
=head4 L<Num|/type/Num> literals
251+
252+
Scientific notation with an exponent to base ten after an C<e> produces
253+
L<floating point number|/type/Num>:
254+
255+
1e0
256+
6.022e23
257+
1e-9
258+
-2e48
259+
260+
=head4 L<Complex|/type/Complex> literals
261+
262+
L<Complex|/type/Complex> numbers are written either as an imaginary number
263+
(which is just a rational number with postfix C<i> appended), or as a sum of
264+
a real and an imaginary number:
265+
266+
1+2i
267+
6.123e5i
268+
269+
=begin comment
220270
221271
=head3 Pair literals
222272

0 commit comments

Comments
 (0)