Skip to content

Commit

Permalink
fixed quotient and modulus for non-integer domains
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Aug 10, 2024
1 parent 76af349 commit 5254fb3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
19 changes: 5 additions & 14 deletions M2/Macaulay2/m2/reals.m2
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,11 @@ new CC from RawRingElement := (CCC,x) -> ( assert( CCC === CC ); rawToCC x)

CC.InverseMethod = y -> conjugate y / y^2

scan((QQ,RR,CC), F -> (
F // F := (x,y) -> if y == 0 then 0_F else x/y;
F % F := (x,y) -> if y == 0 then x else 0_F;
F // ZZ := (x,y) -> x // y_F;
F % ZZ := (x,y) -> x % y_F;
))

scan((RR,CC), F -> (
F // QQ := (x,y) -> x // y_F;
F % QQ := (x,y) -> x % y_F;
))

CC // RR := (x,y) -> x // y_CC;
CC % RR := (x,y) -> x % y_CC;
installDivMod = F -> (
F // Number := (x, y) -> if y == 0 then 0_F else floor(x / y_F);
F % Number := (x, y) -> if y == 0 then x else x - y * (x // y);
)
apply({QQ, RR, CC}, installDivMod)

-- functions
realPart Number := realPart0
Expand Down
13 changes: 13 additions & 0 deletions M2/Macaulay2/tests/normal/reals.m2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
scan({QQ, RR, CC}, F -> (
assert(13.3_F // 4_RR - 3.0 < 1e-15);
assert(13.3_F % 4_RR - 1.3 < 1e-15);
assert(13.3_F // 4_QQ - 3.0 < 1e-15);
assert(13.3_F % 4_QQ - 1.3 < 1e-15);
assert(13.3_F // 4_ZZ - 3.0 < 1e-15);
assert(13.3_F % 4_ZZ - 1.3 < 1e-15);
))

scan({ZZ, QQ, RR}, F -> (
assert((pi*ii) // 3_F < 1e-15);
assert((pi*ii) % 3_F == pi*ii);
))

0 comments on commit 5254fb3

Please sign in to comment.