Questions tagged [rational-number]

A rational is a number that can be expressed as the ratio of two integers.

In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, p and q, with the denominator q not equal to zero. Since q may be equal to 1, every integer is a rational number. The set of all rational numbers is usually denoted by a boldface Q (or blackboard bold (\mathbb{Q} in LaTeX), Unicode ℚ); it was thus denoted in 1895 by Peano after quoziente, Italian for "quotient".

110 questions
1
vote
1 answer

java syntax help for ADT rational implementation [Error: cannot find symbol]

so I am trying to build this ADT for rational numbers in java but for some reason I keep getting this error that says cannot find symbol when trying to compile. What em I doing wrong? Is this error because of my syntax? Author: Juan Suarez // Class…
Juan Suarez
  • 31
  • 1
  • 3
1
vote
2 answers

About rational number in java programming, to calculate (1/2+3/4+...+99/100)^2

The purpose of this code is to calculate (1/2+3/4+...+99/100)^2. But my loop can't be executed correctly. The result of r1 is 3/4 instead of 99/100, what's wrong with my code? I think my loop can be run because the y I can get it correctly. So…
Ben.W
  • 65
  • 2
  • 3
  • 10
1
vote
1 answer

Display illimited rational number defined by two integer

I'm working on a Rational number class in c++. The Rational number is defined by two int (numerator and denominator). I would like to display it properly as digit number. for now, I determine if the number is an "illimited" or a limited digit…
Hugo Hismans
  • 173
  • 1
  • 1
  • 8
1
vote
1 answer

C++11 regex confusion

I've an python regex : \A\s* # optional whitespace at the start, then (?P[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P\d*) # numerator…
MaxC2
  • 343
  • 3
  • 10
1
vote
1 answer

Why is a decimal.Decimal object not considered rational?

A python Decimal stores a base 10 number, which can be thought of as a ratio with a power of 10 on the bottom. So why does this fail? from decimal import Decimal from numbers import Rational assert issubclass(Decimal, Rational)
Eric
  • 95,302
  • 53
  • 242
  • 374
1
vote
0 answers

Why are rational numbers suddenly appearing in JSON/Rails

I use Rails to generate JSON for a javascript charting library (High Charts). There are a few places where I use integer arithmetic to calculate percentages in bar charts like this (simplified example): def to_json data.map{|numerator, denominator|…
Kevin Lawrence
  • 698
  • 7
  • 23
1
vote
1 answer

Implementing comparable interface to rational class(java)

I am a beginner in Java and this is my first time using Comparable interface. I don't understand why it keeps returning zero when comparing r1 and r2. Can someone explain to me what is wrong with my code? Thank you. public class Rational implements…
user7571195
1
vote
1 answer

Main Method for My Rational Code

So I have finished the code to my rational tests involving addition, subraction etc for rational numbers. I'm stuck trying to make the main class that actually outputs the code. Here is my code for the Rational class : package rational; public…
1
vote
3 answers

Rational Class - Unable to Reduce fraction and Divide

My Rational Class is supposed to add, subtract, multiply, and divide fractions so when called in the Main Class, it will perform these actions. However, I can't seem to reduce my fractions (gcd) properly to get the right answer and the division…
1
vote
0 answers

Rational Numbers in Java

I'm doing the following for a lab, and am getting everything to compile with the file they gave us apart from the last method named "divide". The point of it is to do different operations using Rational numbers. My This is my code for the divide…
Jack
  • 11
  • 4
1
vote
0 answers

boost's gmp_rational type is very slow when performing comparison operations

I'm comparing the performance of boost's gmp_rational datatype with the SolverFoundation.Rational type of C#. Performing arithmetic with gmp_rational is much faster than C# SolverFoundation.Rational, except for comparison operations. I have…
NMO
  • 748
  • 8
  • 16
1
vote
1 answer

An efficient way to perform rational addition in GNU Octave / Matlab

Given F, an nx2 matrix of fractions ([num1, den1; num2, den2; ...]), how to efficiently compute the fraction that results from their addition? (i.e. [F(1,1)*F(2,2)*...*F(n,2) + F(1,2)*F(2,1)*F(2,3)*...*F(n,2) + ... , F(1,2)*...*F(n,2)]). The result…
nightcod3r
  • 752
  • 1
  • 7
  • 26
1
vote
3 answers

Can you implement and override the list.sort() method to sort a list of rational numbers?

So I've been given the following problem: Write a program that creates a List of Rationals and sorts them into increasing order. Use appropriate methods from the Collections Framework classes to sort the elements into increasing order. I've…
Andrew Coates
  • 119
  • 2
  • 12
1
vote
1 answer

Adding Tag to the type declaration

I need to add a tag value in the Type declaration as shown here: The problem is that I keep getting the Tag name instead of the Tag value in the generated code. as follows. any clues? My original need was to make some #define lines and I was…
Isyola
  • 130
  • 1
  • 8
1
vote
1 answer

Generate next rational number in agda

How can i generate the next rational number into 2 integer variables. For example, (1,1) (2,1) (1,2) (1,3) (3,1) .. I have the algorithm to generate it : if(n % 2 == d % 2) { n++; if(d > 1) d--; } else{ d++; if(n > 1) n--; } The problem…
ajayv
  • 641
  • 6
  • 21