-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for bin, oct and hex literals * Update some places in the std lib where octal literals are better * Add docs for number formats
- Loading branch information
1 parent
d6b0fd9
commit c32c5ce
Showing
11 changed files
with
192 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Number formats | ||
--- | ||
|
||
Spice supports four different number formats to cover as many use-cases as possible. | ||
|
||
## Decimal format (base 10) | ||
|
||
Decimal numbers can be written in two ways in Spice. The implicit way: | ||
|
||
```spice | ||
int i32 = 123; | ||
short i16 = 123s; | ||
long i64 = 123l; | ||
``` | ||
|
||
or the explicit way: | ||
|
||
```spice | ||
int i32 = 0d123; | ||
short i16 = 0d123s; | ||
long i64 = 0d123l; | ||
``` | ||
|
||
## Binary format (base 2) | ||
|
||
```spice | ||
int i32 = 0b1010; | ||
short i16 = 0b1010s; | ||
long i64 = 0b1010l; | ||
``` | ||
|
||
## Hexadecimal format (base 16) | ||
|
||
```spice | ||
int i32 = 0xA76E; | ||
short i16 = 0xA76Es; | ||
long i64 = 0xA76El; | ||
``` | ||
|
||
## Octal format (base 8) | ||
|
||
```spice | ||
int i32 = 0o1274; | ||
short i16 = 0o1274s; | ||
long i64 = 0o1274l; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.