tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

46 lignes · 1248 octetsBrut · Historique
1// Int arithmetic at its edges: the native fast paths (louise_rt.h) must agree
2// with the interpreter (issue #61).
3
4import std/io
5
6fn cmp :: a: Int b: Int -> String
7{
8 match compare a b { Lt -> "lt", Eq -> "eq", Gt -> "gt" }
9}
10
11pub fn main :: -> () / <io>
12{
13 let big = 4611686018427387903
14 let small = 0 - big - 1
15 io.println
16 ( show (7 / 2) <> " " <> show (0 - 7 / 2) <> " " <> show ((0 - 7) / 2)
17 <> " "
18 <> show (7 / (0 - 2))
19 )
20 io.println
21 ( show (7 % 3) <> " " <> show ((0 - 7) % 3) <> " " <> show (7 % (0 - 3))
22 <> " "
23 <> show (small % (0 - 1))
24 )
25 io.println
26 ( show (big * 1) <> " " <> show (small * 1) <> " "
27 <> show (1073741824 * 1073741823)
28 <> " "
29 <> show ((0 - 3) * 5)
30 )
31 io.println (show (small / 2) <> " " <> show (big / (0 - 1)))
32 io.println
33 ( cmp small big <> " " <> cmp big big <> " " <> cmp 0 (0 - 1) <> " "
34 <> show (small == small)
35 <> " "
36 <> show (small == big)
37 )
38 let zero = big - big
39 io.println (show (1 / zero))
40}
41//> 3 -3 -3 -3
42//> 1 -1 1 0
43//> 4611686018427387903 -4611686018427387904 1152921503533105152 -15
44//> -2305843009213693952 -4611686018427387903
45//> lt eq gt True False
46//! panic: division by zero