-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcalculator.cpp
More file actions
executable file
·56 lines (50 loc) · 1.07 KB
/
calculator.cpp
File metadata and controls
executable file
·56 lines (50 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//usr/bin/env g++ -Based -std=c++23 -O2 -o - "${@:0}"; exit
#include "gil/std.hpp"
using namespace gil::std;
enum {
LHS,
RHS,
OP,
RES,
};
using Num = long long int;
volatile auto run = main<{
// divine punishment for not entering reasonable input
var_(LHS) = io::read<Num>(),
var_(OP) = io::read<char>(),
var_(RHS) = io::read<Num>(),
switch_(var_(OP))(
case_('+')(
var_(RES) = var_(LHS) + var_(RHS)
),
case_('-')(
var_(RES) = var_(LHS) - var_(RHS)
),
case_('*')(
var_(RES) = var_(LHS) * var_(RHS)
),
case_('/')(
if_(var_(RHS) != 0)(
var_(RES) = var_(LHS) / var_(RHS)
)->else_(
str::puts(str::literal("Division by zero!\n"))
)
),
case_('%')(
if_(var_(RHS) != 0)(
var_(RES) = var_(LHS) % var_(RHS)
)->else_(
str::puts(str::literal("Modulo zero!\n"))
)
),
default_(
str::puts(str::literal("Invalid OP: ")),
putc_(var_(OP)),
putc_('\n')
)
),
if_(var_(RES) != none_)(
io::write<Num>(var_(RES)),
putc_('\n')
)
}>;