Numeric Literals and Suffixes

Summary

Creates a numeric value.

Syntax

number[suffix]

Parameters

number
A number. This can be a whole number, decimal number, hexadecimal literal, or octal literal.
suffix
An optional suffix for whole numbers and decimal numbers. Possible values: f, F, d, D, L, UL

Description

Numeric literals create a numeric value.

Integrals without a suffix are interpreted in this order: int, unsigned int, long, unsigned long, byte, signed byte, short, unsigned short, and char. If the integral value does not "fit" within any specified types, such as possible function overloads or a specified variable type, an error will be raised at compile time.

Decimal numbers without a suffix are interpreted as double.

Suffixes

Numeric suffixes allow "overriding" the default type for a number. For example, 1.1 is interpreted as a double by default. However, by adding an f or F suffix, it can be treated as a float:

1
2
1.1;  // 'double'
1.1f; // 'float'

The following is a list of available suffixes:

Suffix Type
L long
UL unsigned long
f float
F float
d double
D double

Lowercase l and ul are not supported for long and unsigned long, respectively. This was a design decision to avoid confusion between lowercase l and the numeric value 1 (one) in some fonts.

Scientific Notation

JS++ supports scientific notation using the e or E syntax:

1
2
3
4
10e1;   // 100
10e2;   // 1000
1.5e2;  // 150
1.5e-2; // 0.015

This syntax is a short-hand for the following mathematical formula:

m × 10n

Hexadecimal Literals

JS++ supports hexadecimal literals:

1
2
3
4
0xF;  // 15
0xFF; // 255
0X9;  // 9
0X4;  // 4

Hexadecimal literals support scientific notation, but they do not support decimals or numeric suffixes.

Octal Literals

Octal literals are used for representing numbers in base 8 form:

1
010; // 8

See Also

Share

HTML | BBCode | Direct Link