# 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.

68 questions
Filter by
Sorted by
Tagged with
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 ...
78 views

### Fractions in C++

I started learning classes and operator overloading in C++. To test my skills I decided to make a Fraction class with all necessary operations. I would appreciate improvements and suggesstions on my ...
3k views

### Rational implementation

Can someone review this? The header file can be viewed here. ...
163 views

Best rational approximations is a technical term and not subjective. The best rational approximations are the convergents of a value plus it's semi convergents that are closer to the original value ...
241 views

### Clojure performance for solving Project Euler 72 (counting proper reduced fractions)

Challenge This is a solution of Project Euler 72 in Java. How may proper reduced fractions $\dfrac{n}{d}$ are there, where $n < d \le 10^6$? Code ...
39k views

### Simplify a fraction

I have been learning Python for a while (my first programming language) in my spare time. Since it's been 20 years since math class, and I didn't get very far with that, I just brushed up on pre-...
644 views

### Parsing a BigRational efficiently

I'm using the BigRational beta off the BCL CodePlex (bcl.codeplex.com), and I realized it had no parsing method, so I tried to write one. However, it's quite ...
963 views

### Efficiently finding approximate fraction, with tolerance for fp rounding

I needed to convert floating point numbers to int/int fractions. Python technically has this functionality, but has issues with rounding errors: ...
127 views

I'm a bit of a beginner when it comes to Java, and I created this small code to help me grasp a few small subjects. It allows its user to convert a radical to a degree measure and a degree measure to ...
6k views

### A simple Fraction class

My code seems to work fine. However, I feel like it is a bit too long (fraction.cpp). I really want to create simple, readable, and efficient code. Sample Run: Here is the fraction.h file: ...
3k views

### Calculate with fractions

This program is a solution to homework given by our professor. So I want my program to be the most beautiful program ever written. Therefore I want to know where I could improve the quality of the ...
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 ...
16k views

### A Fraction class in C++

I am trying to learn clear and concise C++. Currently I'm learning classes in school, and to practice I have made a Fraction class. I'd appreciate any help regarding style, cleanliness or anything ...
6k views

### Program to add two fractions in C

The task was: You’re given A/B and C/D. You will have to calculate A/B + C/D and answer it as E/F. Input specification On the first line you’re given the test case number N. Then there will ...
2k views

### Rational class with Java

Here is a class to handle fractions with Java using BigInteger because it supports gcd calculus. I don't know if BigInteger is the optimal use with fractions, but this is an alternative with fractions....
777 views

### C++ fraction class *Updated

This fraction class is a project I'm working on for fun. I want it to the best it can be. Please let me know if I'm following best procedures or if I'm missing something. **Update So, I took the ...
2k views

### Counting the number of unique fractions read from a text file

I will begin this question with the disclaimer that it is homework but my code is written and working, I just want to know if there any ways in which I can improve what I already have. I want my ...
873 views

### Fraction type in Rust

Inspired by another question here on Code Review, I decided to try implementing a Fraction type in Rust. Requirements: Able to be added, subtracted, multiplied, ...
15k views

### Implementation of a Fraction class in Java

I am writing a bunch of Math related classes:BigInteger,Fraction,matrix,vector,polynomial,set etc.All of these classes will use each other.The classes will either work in decimal format or in Rational ...
5k views

### A minimal Fraction class in C++

I am trying to learn idiomatic Modern C++. I was wondering how you would improve upon this Fraction class. I would really appreciate any help with code organization, cleanliness and anything else that ...
177 views

### 4 distinct integers, whose reciprocals sum up to 1

I wrote the following short python program to solve a math puzzle, which asked for all the 4-tuples of distinct natural numbers whose reciprocals sum up to 1. ...
94 views

### Fraction class with documentation

I have never worked with Ruby before, and thought I'd start working on learning it. For my first little implementation, I have created a simple fraction class. It would be nice if someone would check ...
458 views

### Number representation for a calculator that works with very big numbers

I'm a beginner: I have learned concepts and features which I think I need in my project, but this is my first serious program and it is my internship project. I'm totally confused and need help to ...
2k views

I have created a rationalnumber class and used operator overloading function of C++. My questions are: Have I implemented the class and ...
197 views

### Number class to add/compare different kinds of numbers

I am creating a Number class having Integer and Fraction derive class which add/compare different kinds of numbers. In addition, the caller need not needs to know ...
3k views

Question: Need to create three classes. Number Fraction Integer Requirements The first class should support “display”, “==”, and “+”. "Display" : This operation displays the Number itself in its ...
346 views

### Converting a decimal into a fraction

I have written a small program that converts a decimal number into a reduced fraction representation. I also designed this little program to be fairly robust, so that it can give the correct output ...
101 views

### Fraction or integer parser

Question How can the following implementation of fractionParse be made less ugly? (Preserving unreduced numerators and denominators is supposed to be a feature---...
134 views

### A utility class for fractions

I've been working though Project Euler problems using JavaScript, and along the way I've found it useful to create "classes" for different types of numbers (like an integer that can be arbitrarily ...
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 ...
4k views

### Fraction class in Java

(See the next iteration.) I have this class for representing exact fractions. See what I have: Fraction.java: ...
853 views

### Decimal-to-fraction solver

I have created a program that turns a decimal into a fraction: ...
5k views

### Converting fractions to mixed numbers

I've been making a program for an assignment that converts fractions to mixed numbers, and I'm done, but I was wondering if I could simplify it in any way, since it seems quite complicated right now. ...
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 ...
259 views

### Rational class supporting precise numbers

This is my JavaScript Rational class, similar to other languages' BigFraction class, but with one major difference: This class ...
179 views

### Converting fraction notation in strings to a Rational data type

I've been messing around with a RationalInt type, using a simple int-based structure for the time being. I've created code to ...
2k views

This just adds fractions. For example, if we have a text file with: 1/3 1/2 It will print: 5/6 I would love to hear some ...
128 views

### Rational arithmetic from given input

I'm currently working on this for my own practice. I get 4 digits and an operation. The input is x1 y1 op x2 y2 and the fraction is ...
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. ...
3k views

### Mixed number fractions class

I'm looking for bugs. I tried to test all functionality in a variety of ways. ...
4k views

### Creating and testing a Fraction class

The exercise is as follows: Create a class called Fraction that can be used to represent the ratio of two integers. Include appropriate constructors, properties, and methods. If the denominator ...
2k views

### Rational number implementation

I've been recently working on a custom rational number implementation. Due to not very interesting reasons, using this implementation is not an option. I'd appreciate comments of anyone who has the ...
1k views

### Decimal expansion of a rational number

I wrote a program that does division and either does or doesn't show repeating groups. After designing it the first time I had to redesign it because although it worked it was unnecessarily complex. ...
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 ...
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: ...
2k views

### Unit Tests for a Fraction Class

As my first Java homework, I wrote a class to handle fractions. This Fraction class implements basic operations for the fractions (addition, subtraction, ...
4k views

### Fraction Class in Python

I decided to train myself in OOP with a simple perfect precision Fraction class. ...
28k views

### Mathematical functions on fractions

I have been challenged by @nhgrif to write a Fraction class to better my understanding of OOP. I have found an interesting challenge here (I apologize that the source is not mentioned, I was not able ...