Numbers
Integers and floats to rule the world!
There are two basic kinds of numbers in BoxLang: integers (whole numbers) and floats (have a decimal point). Internally, each BoxLang engine treats them uniquely and backs up each numerical value as a Java class: java.lang.Double
or java.lang.Integer
.
Type | Size (bits) | Min Value | Max Value |
---|---|---|---|
| 32 | -2,147,483,648 (-231) | 2,147,483,647 (231 - 1) |
Type | Size (bits) | Significant Bits | Exponent Bits | Decimal Digits |
---|---|---|---|---|
| 64 | 53 | 11 | 15-16 |
Tip: If you are dealing with currency or tracking precision, please read about precisionEvaluate()
to represent big numbers and precision results: https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/math/precisionevaluate
Also, note that BoxLang will do the auto-casting for you when converting between integers and doubles.
Numeric Type
Once we start looking at functions/closures and lambdas, you will see that you can also type the incoming arguments and results of functions. You also won't need to type it with integer or float, just as numeric:
Operators & Functions
BoxLang offers tons of mathematical operators and functions: https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/math
abs | aCos | arrayAvg |
---|---|---|
arraySum | aSin | atn |
bitAnd | bitMaskClear | bitMaskRead |
bitMaskSet | bitNot | bitOr |
bitSHLN | bitSHRN | bitXor |
ceiling | cos | decrementValue |
expt | fix | floor |
formatBaseN | incrementValue | inputBaseN |
int | log | log10 |
max | min | pi |
precisionEvaluate | rand | randomize |
randRange | round | sgn |
sin | sqr | tan |
Casting/Parsing
BoxLang also has a toNumeric()
function that you can use to cast a value to a number using different radixes.
The parseNumber()
is also used to convert a string number into a numeral system (https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/conversion/parsenumber)
In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers. For example, for the decimal system (the most common system in use today) the radix is ten, because it uses the ten digits from 0 through 9.
Is it a number?
BoxLang provides the isNumeric()
function to determine if the passed value can be converted to a numeric value.
Repeating Instructions
Number variables can be used to repeat instructions. Like in many other languages, BoxLang supports the for
, while
and loop
constructs:
Please note that the syntax varies from tag to script, so refer to the docs for subtle differences. Please also note that you can iterate over structures, arrays, queries, and objects in BoxLang; we will see this in later sections.
See https://boxlang.ortusbooks.com/boxlang-language/reference/components/system/loop for more information
Last updated