mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 05:54:33 +00:00
feat: add std.d
This commit is contained in:
parent
51cae591a3
commit
677ced0fcd
7 changed files with 131 additions and 14 deletions
32
crates/erg_compiler/lib/std.d/Float.d.er
Normal file
32
crates/erg_compiler/lib/std.d/Float.d.er
Normal file
|
@ -0,0 +1,32 @@
|
|||
.Float: ClassType
|
||||
.Float.
|
||||
'''
|
||||
the real part of a complex number
|
||||
'''
|
||||
'''japanese
|
||||
複素数の実部
|
||||
'''
|
||||
Real: Float
|
||||
'''
|
||||
the imaginary part of a complex number
|
||||
'''
|
||||
'''japanese
|
||||
複素数の虚部
|
||||
'''
|
||||
Imag: Float
|
||||
'''
|
||||
Return a hexadecimal representation of a floating-point number.
|
||||
'''
|
||||
'''erg
|
||||
assert (100.0).hex() == "0x1.9000000000000p+6"
|
||||
assert (12.34).hex() == "0x1.8ae147ae147aep+3"
|
||||
'''
|
||||
hex: (self: .Float) -> Str
|
||||
'''
|
||||
Return True if the float is an integer.
|
||||
'''
|
||||
'''erg
|
||||
assert (1.0).is_integer()
|
||||
assert not (1.1).is_integer()
|
||||
'''
|
||||
is_integer: (self: .Float) -> Bool
|
28
crates/erg_compiler/lib/std.d/Int.d.er
Normal file
28
crates/erg_compiler/lib/std.d/Int.d.er
Normal file
|
@ -0,0 +1,28 @@
|
|||
.Int: ClassType
|
||||
.Int.
|
||||
'''
|
||||
Number of ones in the binary representation of the absolute value of self.
|
||||
|
||||
Also known as the population count.
|
||||
'''
|
||||
'''japanese
|
||||
2進数表現の絶対値の中の1の数。
|
||||
|
||||
ハミング重みとも呼ばれる。
|
||||
'''
|
||||
'''erg
|
||||
assert bin(13) == "0b1101"
|
||||
assert 13.bit_count() == 3
|
||||
'''
|
||||
bit_count: (self: .Int) -> Nat
|
||||
'''
|
||||
Number of bits necessary to represent self in binary.
|
||||
'''
|
||||
'''japanese
|
||||
2進数表現においてselfを表すのに必要なビット数。
|
||||
'''
|
||||
'''erg
|
||||
assert bin(37) == "0b100101"
|
||||
assert 37.bit_length() == 6
|
||||
'''
|
||||
bit_length: (self: .Int) -> Nat
|
33
crates/erg_compiler/lib/std.d/Str.d.er
Normal file
33
crates/erg_compiler/lib/std.d/Str.d.er
Normal file
|
@ -0,0 +1,33 @@
|
|||
.Str: ClassType
|
||||
.Str.
|
||||
'''
|
||||
Return a capitalized version of the string.
|
||||
|
||||
More specifically, make the first character have upper case and the rest lower
|
||||
case.
|
||||
'''
|
||||
'''erg
|
||||
assert "hello".capitalize() == "Hello"
|
||||
assert "HELLO".capitalize() == "Hello"
|
||||
'''
|
||||
capitalize: (self: .Str) -> .Str
|
||||
'''
|
||||
Return a version of the string suitable for caseless comparisons.
|
||||
'''
|
||||
'''erg
|
||||
assert "camelCase".casefold() == "camelcase"
|
||||
assert "CamelCase".casefold() == "camelcase"
|
||||
assert "FULLCAPS".casefold() == "fullcaps"
|
||||
assert "snake_case".casefold() == "snake_case"
|
||||
'''
|
||||
casefold: (self: .Str) -> .Str
|
||||
'''
|
||||
Return a centered string of length width.
|
||||
|
||||
Padding is done using the specified fill character (default is a space).
|
||||
'''
|
||||
'''erg
|
||||
assert "hello".center(10) == " hello "
|
||||
assert "hello".center(10, "-") == "--hello---"
|
||||
'''
|
||||
center: (self: .Str, width: Int, fillchar: .Str) -> .Str
|
Loading…
Add table
Add a link
Reference in a new issue