18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exceptions 175<br />

The function Rat_Const is used to construct a constant rational number. The second formal parameter may<br />

be omitted when convert<strong>in</strong>g a whole number <strong>in</strong>to a rational number.<br />

function Rat_Const( F:<strong>in</strong> Integer;<br />

S:<strong>in</strong> Integer:=1 ) return Rational is<br />

beg<strong>in</strong><br />

if F = 0 then<br />

return Rational'(0,1);<br />

else<br />

return Simplify( Sign( Rational'( F, S ) ) );<br />

end if;<br />

end Rat_Const;<br />

Note:<br />

A rational constant could have been created by overload<strong>in</strong>g the operator / between two <strong>in</strong>tegers to<br />

deliver a rational number. The disadvantage of this approach is that the two dist<strong>in</strong>ct mean<strong>in</strong>gs for /<br />

must be dist<strong>in</strong>guished between <strong>in</strong> a program section.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!