Questions tagged [rational-numbers]

In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, with the denominator q not equal to zero.

Filter by
Sorted by
Tagged with
7
votes
5answers
3k views

Fraction class implemented in Objective-C

Inspired by this question: Fraction (rational number) structure with custom operators, I have written this class for doing some simple work with fractions. ...
11
votes
2answers
13k views

Implementation of a Rational Number class in C++

First of all, disclaimer; this is for a school assignment. I hope I'm not doing anything inappropriate by asking for input on it, but if it makes a difference, the assignment has already been ...
17
votes
7answers
2k views

My Rational struct, version 2

I implemented most of the suggestions from Version 1. Thanks to all who took time to review and offer really good comments. ...
10
votes
5answers
4k views

Fraction class in Java

(See the next iteration.) I have this class for representing exact fractions. See what I have: Fraction.java: ...
8
votes
3answers
784 views

Risk battle simulator v1

I've written a program to find the odds of either side winning a battle in Risk, and how many men they would have left. I've finished, but I feel that it can be improved since it doesn't function if ...
8
votes
4answers
726 views

My Rational struct, version 1

I have written a Rational struct for working with rational numbers, i.e. Rational(int numerator, int denominator). A recent ...
11
votes
2answers
2k views

A fraction of the code

Following up on this post, and including some major changes suggested, here's the revised code. Changes include: No longer keeping an IFormatProvider at instance ...
11
votes
1answer
1k views

Formattable Fraction

I have written this small little program, to test how my Fraction type behaves when used with and without a custom ...
10
votes
5answers
2k views

Using TryXXX pattern to avoid exceptions

I have been using the TryXXX and GetXXX pattern lately to give clients a choice whether to trap an exception or to read a boolean. An example of this concept would be ...
8
votes
2answers
3k views

Fraction (rational number) structure with custom operators

First, the struct itself: ...
7
votes
2answers
3k views

Cleaning up Reverse Polish Notation evaluator

I was wondering if anyone had some general clean up advice on my code. I believe that more helper functions would be my case but I could be wrong. 30 lines maximum per method is my rule. I can't seem ...
4
votes
2answers
527 views

Fraction class in Java - follow-up

(See the previous iteration.) I have improved my Fraction implementation taking the answers in the previous iteration into account. Differences Both numerator ...
-1
votes
4answers
2k views

Finding the lowest terms for fractions in C#

I have been working on this Rational Operations calculator where you can input two rational numbers and can add, subtract, multiply and divide and the final output is the reduced answer. For example: ...