Number API Functions: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 44: Zeile 44:
=== Arithmetic ===
=== Arithmetic ===
The usual arithmetic operators.<br>
The usual arithmetic operators.<br>
[[Datei:point_right.png|20px]] Notice, that they are evaluated left to right, without special precedences. Thus you should always use parentheses to group expressions when are than one operator is in an arithmetic expression.
[[Datei:point_right.png|20px]] Notice, that they are evaluated left to right, without special precedences.
Thus you should always use parentheses to group expressions when there are two or more operators in an arithmetic expression.


''aNumber'' '''+''' ''aNumber'' => Number
''aNumber'' '''+''' ''aNumber'' => Number

Version vom 20. Dezember 2019, 15:44 Uhr

This document lists most useful (and most often needed) functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.

Reference: Integer Float Fraction FixedPoint Complex which all inherit from Number

Back to Useful API Functions

Testing[Bearbeiten]

Check if number is not infinity and not NaN:

aNumber isFinite    => Boolean

Check if number is either positive infinity (INF) or negative infinity (-INF):

aNumber isInfinite  => Boolean

Check if number is NaN ("Not a Number"):

aNumber isNaN    => Boolean
Sign checks[Bearbeiten]
aNumber negative => Boolean

same as aNumber < 0

aNumber positive => Boolean

same as aNumber >= 0

aNumber strictlyPositive => Boolean

same as aNumber > 0

Misc Properties[Bearbeiten]
anInteger isPrime => Boolean

true if the number is a prime number

anInteger isPowerOf2  => Boolean

true if there exists an n, such that 2ˆn equals the number

anInteger isPowerOf:b => Boolean

true if there exists an n, such that bˆn equals the number

Queries[Bearbeiten]
anInteger nextPrime => anInteger
anInteger nextPowerOf2 => anInteger

Arithmetic[Bearbeiten]

The usual arithmetic operators.
Point right.png Notice, that they are evaluated left to right, without special precedences. Thus you should always use parentheses to group expressions when there are two or more operators in an arithmetic expression.

aNumber + aNumber  => Number
aNumber - aNumber  => Number
aNumber * aNumber  => Number
aNumber / aNumber  => Number

Truncated result (towards the next smaller integer i.e. towards negative infinity):

aNumber // aNumber  => Integer

Examples:

 100 // 3
 => 33
 -100 // 3
 => -34



Copyright © 2014-2024 eXept Software AG