//implementation of the simplest arithmetic on rational numbers //represented as: a b/c with sign. //author: Michal Pilipczuk //XIV Secondary School, Warsaw, Poland unit ulamki; interface type ulam=record znak:longint; //sign a:qword; b:qword; c:qword; end; //type of fraction procedure wypisz(o:ulam); //writes fraction function app(xu:ulam):ulam; //makes a fraction appropriate so by.a) then mna:=(x.ay.znak then mn:=(x.znak0) and (y.znak>0)) then add:=adda(x,y) else begin if x.znakpom1.b*x.c then begin dec(pom2.a); pom2.b:=(pom1.b*x.c+pom2.c); pom2.b:=(pom2.b-x.b*pom1.c); add:=app(pom2); end else begin pom2.b:=pom1.b*x.c-x.b*pom1.c; add:=app(pom2); end; end; end; end; end; function multi(e,f:ulam):ulam; var pomy,pomq2,pomq3:ulam; begin pomq2.znak:=1; pomq3.znak:=1; pomq2.a:=e.a*f.a; pomq2.c:=f.c; pomq2.b:=e.a*f.b; pomq2:=app(pomq2); pomq3.a:=0; pomq3.c:=e.c; pomq3.b:=f.a*e.b; pomq3:=app(pomq3); pomy:=adda(pomq2,pomq3); pomy.b:=pomy.b+e.b*f.b; pomy.znak:=e.znak*f.znak; multi:=pomy; end; function kwa(e:ulam):ulam; var pomq2:ulam; begin pomq2.znak:=1; pomq2.a:=e.a*e.a; pomq2.c:=e.c; pomq2.b:=2*(e.b*e.a); pomq2:=app(pomq2); pomq2.b:=pomq2.b*pomq2.c+e.b*e.b; pomq2.c:=pomq2.c*pomq2.c; kwa:=app(pomq2); end; end.