Syntax
This part of the documentation explains the syntax of valid SpeedCrunch input. As you will see, SpeedCrunch honors most conventions for mathematical expressions. You will find using SpeedCrunch to be very natural and intuitive, especially so if you are already familiar with a programming language.
Number Notation
Decimal Form
When you would like to specify a non-integer value, simply enter the number as you would write it on paper,
with either a period (.) or a comma (,) as the decimal separator.
Accepted decimal separator and grouping conventions depend on the selected
Number Format.
Trailing zeros after the decimal point (like in 12.300) or leading zeros before it (0012.3) are redundant and can be included or omitted to the user’s preference. Expressions like .5 as a shorthand notation for 0.5 are also permitted.
Digit Grouping Separators
To improve readability, SpeedCrunch accepts grouping separators inside number literals. Grouping separators are optional and ignored during evaluation.
Allowed grouping separators are characters that are not letters or digits and are not number operators. In practice, this includes many punctuation and symbol characters, for example:
_(underscore):12_345_678Space (U+0020):
12 345 678Currency symbols:
$12,345,€12 345,12¥345
Not allowed as grouping separators:
Letters from any language (for example
天,é,Ж)Digits from any language
Radix characters (
.or,depending on settings) when they are used as decimal separatorsOperator characters and other reserved syntax tokens
Some characters cannot be used for digit grouping because they already have an assigned meaning in expressions:
#starts hexadecimal number notation (for example#FF).!is the factorial operator (for example5!).:is used in sexagesimal time/angle notation (for example12:34:56).°is used in sexagesimal angle notation (for example12°34'56).′is used in sexagesimal angle notation (for example12°34′56″).&is the bitwise AND operator (for example6 & 3).?starts a comment (for example1+2 ? note).
Examples:
12$345.678$9evaluates as12345.678912天2is rejected (it is not treated as122)
Scientific Notation
When dealing with very small or very large numbers (think the size of an atom or of a galaxy) the notation above is inconvenient. These are more commonly expressed in scientific notation; for instance, 1.234*10-9 is preferable to 0.000000001234.
Naturally, in SpeedCrunch this could be written as 1.234*10^-9, but there’s also a shorthand notation: 1.234e-9. Here, the e represents *10^, but it is considered a part of the number literal and treated with higher precedence. For example, 1e2^3 is equivalent to (1e2)^3 = 100^3. The scale of a number (sometimes called its exponent) always begins with the scale character E or e followed by a signed integer. So e+10, e-4, E-0 are all valid scale expressions. If the sign is ‘+’, you may simply omit it: e0, E10. The significand (i.e. the part preceding the exponent) is required; exactly one exponent must be specified.
Equivalent examples:
98e3
98*10^3
98x10³
|
Compared to most calculators, SpeedCrunch can accept very large numbers without overflowing (e.g. both 1e+536870911 and 1e-536870911 are still valid). However, only about 78 significant digits are stored at any point. Any digits beyond that are lost.
Non-Decimal Bases
In addition to decimal (base-10) numbers, SpeedCrunch provides support for binary (base-2), octal (base-8) and hexadecimal (base-16) numbers. You can enter a number in any of these bases by marking it with the corresponding prefix:
0bor0Bfor binary, e.g.0b10010.0oor0Ofor octal, e.g.0o1412.0dor0Dfor decimal. These can be omitted since decimal is the default base.0x,0X, or#for hexadecimal. The additional six digits are represented by the upper or lower case lettersatof, e.g.0xdeadbeefor0xDEADBEEF.
You may even enter fractional values in any of these bases. Note that scientific notation is not supported for non-decimal bases, however. Examples:
0b1.01
= 1.25
0xf.a
= 15.625
|
To have SpeedCrunch output its results in a base other than decimal, you may use one of the functions bin(), oct(), dec(), or hex():
hex(12341)
= 0x3035
|
The effect of these functions only applies to the immediate result and doesn’t carry to future operations:
0x2 * hex(12341)
= 24682
|
The same applies to sci() and eng(): they only affect the formatted display of the immediate value, not the numeric value used in later arithmetic. In particular, operand order does not matter:
1 + sci(123456.789)
= 123457.789
sci(123456.789) + 1
= 123457.789
|
For explicit decimal exponent notations, use sci() (scientific notation) or eng() (engineering notation):
sci(12341)
= 1.2341e4
eng(12341)
= 12.341e3
|
To force the exponent used by eng(), pass an optional second argument. It accepts either a direct exponent that is a multiple of 3, or a matching power of ten (including SI prefixes):
eng(0.000123456; [milli])
= 0.123456e-3
eng(0.000123456; -4)
= 1.23456e-4
|
For assembly-style fixed-width formatting, use binpad(), octpad(), or hexpad().
These functions only accept real, dimensionless integer arguments and also only affect the immediate result:
hexpad(15)
= 0x0F
binpad(1536; 32)
= 0b00000000000000000000011000000000
|
To change the base that is used for displaying results, select one of the corresponding settings in . This affects only subsequent calculations/results; existing history entries are not rewritten.
SpeedCrunch stores integers with a precision of up to 256 bits. Since this would be unwieldy, the binary representation of a negative number in SpeedCrunch is not its two’s complement. Instead, like with other bases, the value and the sign are represented separately:
bin(-1)
= -0b1
|
See mask() and unmask() to convert a negative number into the two’s complement form.
Any integer larger than the 256-bit limit will be silently converted into a floating point number, making it susceptible to rounding errors.
To specify large integers, using the shift operators (1 << n) is preferable to exponentiation (2 ^ n) as the latter are floating point
calculations and thus susceptible to rounding errors.
Sexagesimal Values
New in version 1.0.
Sexagesimal values in SpeedCrunch are angle degrees or time values represented with minutes and seconds.
When sexagesimal mode is selected in , dimensionless and time results are displayed as sexagesimal values. All other results are displayed as fixed-point decimal values. Actual sexagesimal math depends on the result. Dimensionless results are handled as degrees with minutes and seconds generated from the decimal part. With time dimension results, base unit is second and the integer part is divided to minutes and hours.
In input, characters ° (degree), : (colon), ′ (prime) and ″ (double prime) can be used for entering sexagesimal values. Degree sign ° separates degrees and minutes. First colon character : separates hours and minutes. Prime ′ or second colon character : separates minutes and seconds. Additionally, postfix double prime ″ can be used as an arc second unit. ASCII single quote ' and double quote " are accepted as aliases and are normalized to ′ and ″ on editor insertion/paste. Because the degree sign is difficult to produce from keyboard, at sign @ is automatically converted to it.
Amount of minutes or seconds is not limited to values below 60. It is possible to input time 90 minutes after noon:
12:90
= 13:30:00
|
Dimensionless input values are automatically considered to be in current angle mode. For example, in radian mode:
pi
= 180°00'00
|
For trigonometric input, explicit angle units override angle mode. For example,
cos(pi*[rad]), cos(180*[deg]), cos(200*[gon]) and
cos(0.5*[turn]) all evaluate to -1 regardless of the global angle mode.
The aliases deg for degree, gon for gradian, and rev for
revolution are supported. revolution is equivalent to turn (that is,
2*pi radians).
deg is normalized to ° in autocomplete insertion and displayed result
units.
Only last part of sexagesimal input value can contain decimals.
Following tables show some possible input notations and their results in both fixed-point decimal and sexagesimal modes. Sexagesimal round-trips (for example arcsecond → DMS → radians) are designed to keep precision drift negligible. In the first table, fixed-point decimal values assume angle mode is set to degrees:
Input |
Fixed-Point Decimal |
Sexagesimal |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Use canonical symbols ′ and ″ (insertable with ' and "),
or the aliases arcmin and arcsec. Full names arcminute and
arcsecond are also accepted.
Input |
Fixed-Point Decimal |
Sexagesimal |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note that when entering time values with colons, no additional dimension units are needed. Formatting itself works as an unit.
Operators and Precedence
When writing an expression like 10+5*4, which operation will be executed first? The common rules of operator precedence tell us that in this case multipication shall be computed first, hence the result is 30. We also distinguish unary operators (which act on a single number/operand) and binary operators (which link two operands).
SpeedCrunch supports the following operators, listed in order of decreasing precedence:
Operator |
Description |
Examples |
|---|---|---|
|
|
|
|
|
|
|
New in version 1.0: Contextual percent semantics. |
|
|
New in version 1.0: Integer superscript powers and |
|
|
New in version 1.0. |
|
|
|
|
|
Multiplication and division
New in version 0.12: Implicit multiplication was added SpeedCrunch 0.12. New in version 1.0: Multiplication and division symbol aliases. Improved explicit interpretation/association in results. |
|
|
New in version 1.0: Addition and subtraction symbol aliases. |
|
|
|
|
|
|
|
|
|
|
|
|
|
For negative bases, fractional powers return the principal complex root.
Use cbrt() when you specifically need the real cubic root of a real
negative value.
Complex Numbers
New in version 0.12.
SpeedCrunch supports complex-number expressions by default. Enter the imaginary
unit as i or j:
j^2
= -1
(5+3j)/(8-2j)
= 0.5+0.5j
|
Syntax note: 5j means 5*j, while j5 is a variable named j5.
Write j*5 explicitly if needed.
The displayed imaginary-unit symbol is configurable in . The displayed complex form is configurable in .
You can enter complex numbers in phasor notation with ∠. The expression
r ∠ θ is interpreted as r * cis(θ). The phase follows the current angle
mode unless it has an explicit angle unit:
3 ∠ 90°
= 3j
3 ∠ 200 [gon]
= -3
|
Not every function accepts complex arguments. Refer to each function entry in the reference.
Caution: fractional powers return principal complex roots. For example,
x^(1/3) may be non-real. In contrast, cbrt() always returns the real
cubic root for real inputs.
Comments
The question mark character
?starts a comment. Everything from?to the end of the line is ignored by the evaluator:A line can also be comment-only. If the first non-space character is
?, the whole line is treated as a comment: