/
TODO
60 lines (46 loc) · 1.7 KB
/
TODO
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
57
58
59
60
BEFORE CONTINUING:
-> Make All Types Immutable, and always return new ones.
(we really want rat() and irrat() to work like the native types, which are all immutable "replace with a new one
every time" objects.)
1) Arithmetic functions for rationals:
the following "dunder" methods must be implemented on rat and rat.FactorisedInt:
all variants of all binary arithmetic operations:
add[, radd, iadd] DONE
sub DONE
mul DONE
div - always give same in rationals. DONE
truediv / DONE
pow - raise an ValueError if argument is not an integer.
and unary ones:
pos
neg
abs
invert - should return the inverse of the rational, with the numerator and denominator swapped.
floor
ceil
trunc
(and, or and xor will be excluded.)
comparisons:
lt
le
gt
ge
eq
ne
(do not implement cmp, as the numerical values cannot necessarily be represented in normal python datatypes.)
type conversions and unitary tests:
int
(long - same as int)
float
complex
oct - raise an ValueError if not an integer.
hex - raise an ValueError if not an integer.
index - raise an IndexError if not an integer.
coerce
representations:
str - double precision floating point style representation, or integer if exact.
repr - 'rat(numerator, denominator)'. not optimised to also store the prime factors, but could be later.
format - allows arbitrary precision representation in any base.
hash - raise an ValueError if not an integer.
nonzero
2) irrationals.