tomo/test/integers.tm

139 lines
2.0 KiB
Plaintext
Raw Normal View History

2024-04-28 11:58:55 -07:00
func main():
2024-04-12 10:09:31 -07:00
>> 2 + 3
= 5
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
>> 2 * 3
= 6
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
>> 2 + 3 * 4
= 14
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
>> 2 * 3 + 4
= 10
2024-02-23 10:34:40 -08:00
>> Int8(1) + Int16(2)
= 3 : Int16
2024-02-23 10:34:40 -08:00
2024-08-12 23:09:18 -07:00
>> 1 << 10
2024-08-12 23:21:21 -07:00
= 1024
2024-02-23 10:34:40 -08:00
2024-11-03 12:48:13 -08:00
!! Signed and unsigned bit shifting:
>> Int64(-2) << 1
= -4 : Int64
>> Int64(-2) <<< 1
= -4 : Int64
>> Int64(-2) >> 1
= -1 : Int64
>> Int64(-2) >>> 1
= 9223372036854775807 : Int64
2024-11-03 12:48:13 -08:00
2024-04-12 10:09:31 -07:00
>> 3 and 2
= 2
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
>> 3 or 4
= 7
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
>> 3 xor 2
= 1
2024-02-23 10:34:40 -08:00
2024-04-12 10:09:31 -07:00
nums := ""
2024-04-28 11:58:55 -07:00
for x in 5:
nums ++= "$x,"
2024-04-12 10:09:31 -07:00
>> nums
= "1,2,3,4,5,"
2024-02-23 10:36:16 -08:00
>> x := Int64(123)
2024-04-12 10:09:31 -07:00
>> x:format(digits=5)
= "00123"
>> x:hex()
= "0x7B"
>> x:octal()
= "0o173"
2024-08-12 23:09:18 -07:00
>> Int64.min
= -9223372036854775808
2024-08-12 23:09:18 -07:00
>> Int64.max
= 9223372036854775807
>> Int32(123):hex()
2024-04-12 10:09:31 -07:00
= "0x7B"
>> Int16(123):hex()
2024-04-12 10:09:31 -07:00
= "0x7B"
>> Int8(123):hex()
2024-04-12 10:09:31 -07:00
= "0x7B"
>> Int(2.1, truncate=yes)
= 2 : Int
2024-08-13 11:13:02 -07:00
do:
>> small_int := 1
= 1
>> max_small_int := 536870911
= 536870911
>> max_i64 := 536870912
= 536870912
>> super_big := 9999999999999999999999
= 9999999999999999999999
>> max_small_int + 1
= 536870912
>> max_small_int + max_small_int
= 1073741822
>> super_big + 1
= 10000000000000000000000
do:
for in 20:
2024-11-03 19:39:46 -08:00
>> n := random:int(-999999, 999999)
>> d := random:int(-999, 999)
!! n=$n, d=$d:
>> (n/d)*d + (n mod d) == n
= yes
>> 0:next_prime()
= 2
>> 7:next_prime()
= 11
#>> 11:prev_prime()
#= 7
>> (and: p:is_prime() for p in [
2, 3, 5, 7,
137372146048179869781170214707,
811418847921670560768224995279,
292590241572454328697048860273,
754893741683930091960170890717,
319651808258437169510475301537,
323890224935694708770556249787,
507626552342376235511933571091,
548605069630614185274710840981,
121475876690852432982324195553,
771958616175795150904761471637,
])!
= yes
>> (or: p:is_prime() for p in [
-1, 0, 1, 4, 6,
137372146048179869781170214707*2,
811418847921670560768224995279*3,
292590241572454328697048860273*754893741683930091960170890717,
])!
= no
2024-09-24 09:40:56 -07:00
>> Int(yes)
= 1
>> Int(no)
= 0
>> Int64(yes)
= 1 : Int64
2024-09-24 09:40:56 -07:00
>> Int64(no)
= 0 : Int64
2024-12-24 11:20:55 -08:00
>> 4:choose(2)
= 6
>> 4:factorial()
= 24