Int and Number classes¶
This page explains the Int and Number classes.
Before reading on, maybe it is helpful to read the following page:
Int class¶
The Int class is the apysc integer type. It can accept numeric values at the constructor, as follows:
import apysc as ap
ap.Stage()
int_1: ap.Int = ap.Int(10)
assert int_1 == 10
import apysc as ap
ap.Stage()
int_1: ap.Int = ap.Int(10)
int_2: ap.Int = ap.Int(int_1)
import apysc as ap
ap.Stage()
int_1: ap.Int = ap.Int(10)
int_2: ap.Int = ap.Int(int_1)
int_2 += 15
assert int_2 == 25
If you specify a float value to the constructor argument, then the Int class floor a value:
import apysc as ap
ap.Stage()
int_1: ap.Int = ap.Int(10.5)
assert int_1 == 10
Number class¶
The Number class is the apysc float type. It can accept numeric values at the constructor, the same as Int:
import apysc as ap
ap.Stage()
number_1: ap.Number = ap.Number(10.5)
assert number_1 == 10.5
number_2: ap.Number = ap.Number(number_1)
number_2 += 10.5
assert number_2 == 21
Note for the Float class alias¶
The Float class is the alias of the Number class. It behaves the same as the Number class. Maybe a Python developer is familiar with its name rather than the Number. On the other hand, the Number is more common in JavaScript than the Float.
import apysc as ap
ap.Stage()
assert ap.Number == ap.Float
assert ap.Number(10.5) == ap.Float(10.5)
Int and Number classes basic interfaces¶
The Int and Number classes have the same interfaces. For more details, please see:
Int class constructor API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] __init__(self, value: Union[int, float, apysc._type.number_value_mixin.NumberValueMixIn], *, variable_name_suffix: str = '', skip_init_substitution_expression_appending: bool = False) -> None
[Interface summary]
Integer class for apysc library.
[Parameters]
value: int or float or Int or NumberInitial integer value. If the
floatorNumbervalue is specified, this class casts it to an integer.
variable_name_suffix: str, default “”A JavaScript variable name suffix string. This setting is sometimes useful for JavaScript debugging.
skip_init_substitution_expression_appending: bool, default FalseA boolean indicates whether to skip an initial substitution expression or not. This class uses this option internally.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> int_val: ap.Int = ap.Int(10)
>>> int_val
Int(10)
>>> int_val == 10
Boolean(True)
>>> int_val == ap.Int(10)
Boolean(True)
>>> int_val >= 10
Boolean(True)
>>> int_val += 10
>>> int_val
Int(20)
>>> int_val = ap.Int(10.5)
>>> int_val
Int(10)
[References]
Number class constructor API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] __init__(self, value: Union[int, float, apysc._type.number_value_mixin.NumberValueMixIn], *, variable_name_suffix: str = '', skip_init_substitution_expression_appending: bool = False) -> None
[Interface summary]
Floating point number class for apysc library.
[Parameters]
value: int or float or Int or NumberInitial floating point number value. This class casts it to float if you specify int or Int value.
variable_name_suffix: str, default “”A JavaScript variable name suffix string. This setting is sometimes useful for JavaScript debugging.
skip_init_substitution_expression_appending: bool, default FalseA boolean indicates whether to skip an initial substitution expression or not. This class uses this option internally.
[Notes]
The Float class is the alias of the Number, and it behaves the same as the Number class.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> number: ap.Number = ap.Number(10.5)
>>> number
Number(10.5)
>>> number == 10.5
Boolean(True)
>>> number == ap.Number(10.5)
Boolean(True)
>>> number >= 10.5
Boolean(True)
>>> number += 10.3
>>> number
Number(20.8)
[References]
value property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a current number value.
[Returns]
value: int or floatCurrent number value.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> int_val: ap.Int = ap.Int(10)
>>> int_val.value
10
>>> int_val.value = 20
>>> int_val.value
20
>>> int_val.value = ap.Int(30)
>>> int_val.value
30
[References]