Sign in to follow this  

Fractions for everyone!

This topic is 4595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, once again folks, I come bearing... something! Anyway, I've been working recently on a fraction class, with multiplication, devision, all that junk.. So, here you have the fruit of my labours.. Anyway, you all can feel free to use this, and if someone could, I'd appreciate it if someone would have a gander through and point out to me the obvious things that I've missed and subsquently screwed up horribly [smile] Readme is included in the header file. Any and all feedback welcome [EDIT] Oh yes, one question.. I was trying to overload the << operator so as to be able to use std::cout with it, and this is what I had my function declaration as: std::ostream & operator<< (std::ostream & os, const Fraction & ref); And of course the obligatory friend declaration inside the Fraction class. However, this yielded a fine crop of errors, err, well, 2 actually. Both of which were syntax errors, one about a missing comma, and one about a misplaced '&' symbol, if I recall correectly. if someone could point out what the heck I was doing wrong, I'd appreciate it!

Share this post


Link to post
Share on other sites
You didn't do any research on existing fraction implementations, did you?

a) Your code breaks when unsigned long isn't 32 bit.
b) Im quite sure that a good least common multiple algorithm is way faster than your primetable.
c) ++ and -- have weird semantics and break comparison operators.
d) Clamping the numerator and denominator to 16-bit values is extremely unintuitive.
e) I'm fairly certain your != is broken.
f) Your binary +,-,*,/ return references and modify one of the operands which again is against intuition
g) Using throw() declarations is considered bad style by most C++ programmers

Share this post


Link to post
Share on other sites
Well, it looks like I got quite a bit wrong then... Anyway, I wasn't doing this for lack of fractions, just to make my own.

Good stuff there, I'll have a look at my code again.. Thanks

Share this post


Link to post
Share on other sites

This topic is 4595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this