Skip to content

Add underscores to numeric literals #1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions guides/hack/02-source-code-fundamentals/19-literals.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ $count = 10 // decimal 10
0XAf << 012 // hexadecimal Af and octal 12
```

Integer literals can also contain underscores as digit separators. They function only as visual aids, they have no
actual meaning. For example:

```Hack
$amount = 394_493_392 // completely equivalent to 394493392
$address = 0x49AD_DF30;
$permission = 012_212_001;
```

## Floating-Point Literals

Floating-point literals typically have an integer part, a decimal point, and a fractional part. They may also have an
Expand All @@ -30,6 +39,12 @@ exponent part. They are written using decimal digits. The type of a floating-po

The predefined constants `INF` and `NAN` provide access to the floating- point values for infinity and Not-a-Number, respectively.

Floating-point literals may also contain underscores as digit separators in the integer part, the fractional part, and the exponent part. For example:

```Hack
123_456.49_30e-30_30
```

## String Literals

A string literal can have one of the following forms:
Expand Down