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
0
votes
1 answer

Rational approximation of rational exponentiation root with error control

I am looking for an algorithm that would efficiently calculate b^e where b and e are rational numbers, ensuring that the approximation error won't exceed given err (rational as well). Explicitly, I am looking for a function: rational exp(rational…
radrow
  • 6,419
  • 4
  • 26
  • 53
0
votes
1 answer

Comparison of rational numbers in GNU/Octave independent of numeric precision

The Octave interpreter evaluates this expression as false: >> 2/3 + 1/6 == 5/6 ans = 0 cause >> 2/3 + 1/6 - 5/6 ans = -1.11022302462516e-16 This can be avoided with the rat (or rats) function, or casting the values, but the resulting expression…
nightcod3r
  • 752
  • 1
  • 7
  • 26
0
votes
1 answer

Exception on Number Class doubleValue

When I run my main method I get the following exception: Exception in thread "main" java.lang.StackOverflowError, followed by this: at Rational.doubleValue(Rational.java:62) like 100+ times. This is for an assignment where the main class is provided…
0
votes
2 answers

Precision issues when converting a decimal number to its rational equivalent

I have problem of converting a double (say N) to p/q form (rational form), for this I have the following strategy : Multiply double N by a large number say $k = 10^{10}$ then p = y*k and q = k Take gcd(p,q) and find p = p/gcd(p,q) and q =…
mcjoshi
  • 299
  • 1
  • 4
  • 11
0
votes
0 answers

Rational Assignment operator

So in this project, I have to create a rationalizer program that helps reduce numbers to a simplified format. The part of the program that I am struggling the most with are the operators with the long parameters.I'm trying to write out the proper…
0
votes
2 answers

Setting hash value (fractions) in ruby and sorting

I receive the following hash: my_hash = {a:(1/20), b:(1/26)} But when I see the hash I get the following: irb(main):019:0> my_hash = {a:(1/20), b:(1/26)} => {:a=>0, :b=>0} irb(main):020:0> my_hash => {:a=>0, :b=>0} As you can see it convert to…
Felipe Maion
  • 336
  • 1
  • 12
0
votes
1 answer

How can i get exposure time by rational from photo properties in android?

I'm writing gallery.But I got double when i use exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME), it should be rational(fraction). If I open system gallery, it is rational.Please help me.Thanks.
jianhua
  • 3
  • 3
0
votes
2 answers

Data race in big.Rat

I used math/big.Rat to represent numbers for accuracy. Denom() returns the denominator of number and Cmp() to compare two numbers. Both of them seems to be a pure read only functions. But when I ran my code with data race enabled, my whole…
IhtkaS
  • 1,314
  • 3
  • 15
  • 31
0
votes
1 answer

What is the difference between `Rational` and `BigNum` implementations

There are a lot of such types for many languages. As far as I know, here is how it works. Rational just stores two separate digits for numerator and denominator (like 3 and 10 for 0.3). BigNum stores each digit of the number in some kind of an…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
0
votes
3 answers

Why won't my method print out?

I've made a main method in one class and a lot of other small methods in another class. When I call on them in my main method using their location and making sure that they would outprint if I called on them, they still don't outprint. Only the…
0
votes
1 answer

Where can I find a (C++ specific) unlimited integer class that works well with boost::rational?

I want to work with rational numbers whose numerator and denominator can go well above the limit of even long long int's, and boost::rational is a nice class that was specifically designed for unlimited integer types. But when I look up what…
Izzhov
  • 163
  • 4
0
votes
1 answer

Calling a Static Method In Main

How do call the last method on this class, in main? I am just trying to return a new Rational object that contains the product of the two parameters. Every time I try to call it in main, I can't use integer in the parameters, since it only accepts…
userb
  • 173
  • 2
  • 15
0
votes
1 answer

How to allow user input of numbers and operators?

how would I add a function that allows the user to input something like 2 + 2 or 10 / 5 then simply run the objects to calculate this as they would when they enter it manually using my "Enter first input" statements. So as part of the assignment I…
androidguy
  • 75
  • 1
  • 1
  • 9
0
votes
1 answer

double precision and peridoc decimals

I'm working on a lisp interpreter and implemented rational numbers. I thought they have the advantage over doubles to be able to represent numbers like 1/3. I did some calculations to compare the results. I was surprised by the results with…
Martin Fehrs
  • 792
  • 4
  • 13
0
votes
1 answer

Haskell use instanced Read in main with Type

How is it possible to use a instanced read in my main? Right now i have the following: data Term = Monom (Float,Int) | Addition (Term,Term) | Subtraction (Term,Term) | Multiplication (Term,Term) | Division (Term,Term) …