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.

Some programming languages provide a built-in (primitive) rational data type to represent rational numbers and to do arithmetic on them (e.g. the ratio type of Common Lisp and analogous types provided by most languages for algebraic computation, such as Mathematica and Maple).

Many languages that do not have a built-in rational type still provide it as a library-defined type.

86 questions
0
votes
1 answer

Using Fractions in Haskell

Continuing from the previous question: Power Series in Haskell I am trying to write the power series in Haskell, e^x = 1 + x + x^2/2! + x^3/3! + ... such that it will output [1,1,1/2,1/6,...] I already have a function here which works without the…
ali
  • 846
  • 2
  • 18
  • 34
0
votes
2 answers

Fastest C++ Rational Number library

I'm using GMPXX wrapper of GMP and it is not fast enough. Is it possible to find some comparison of rational number libraries' speed? During my calculation a very big rational number will appear with 10^100 denominator and same size numerator. Do…
petRUShka
  • 9,812
  • 12
  • 61
  • 95
0
votes
1 answer

Trying to use abstract data types - How to call the methods through inheritence

I am trying to test my abstract class but I am running into problems when I call the methods from the test class. It has been a while since I used Java and I have not used abstract classes before. Any pointers on where I am going wrong would be…
Meowbits
  • 586
  • 3
  • 9
  • 28
-1
votes
1 answer

Rational number calculator

I want to make a rational number calculator, but I don't know how to neglect some characters. E.g., if the program has to calculate the expression "2/9+9/3" and the answer should be in unsimplified form, how to neglect '/' in the above expression…
mohammad bilal
-1
votes
3 answers

Transform rational numbers to integers

How can I transform rational numbers like 1.24234 or 45.314 into integers like 124234 or 45314 also getting the number of decimal digits?
fpiro07
  • 847
  • 1
  • 13
  • 18
-4
votes
1 answer

Selecting rational numbers with maximum sum

I have n rational numbers. Out of that I have to select m numbers such that sum of numerators of m numbers /sum denominators of m numbers is maximum. e.g. if I have 3 numbers 1/1, 1/2, 2/4 and I have to select 2 numbers. Then combinations…
Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76
-4
votes
1 answer

Does sin n have a maximum value for natural number n?

In formal, does there exist such that for all ?
xskxzr
  • 12,442
  • 12
  • 37
  • 77
-4
votes
2 answers

how to make a method return a double

i have the following code and getNom and getdenom are both integers for example 2 and 5. How come I am getting the output of 0.0 here and not 0.4? Thank you. public double divide() { double number = getNom() / getDenom(); …
-5
votes
1 answer

Is my implementation of a Rational number using classes acceptable?

I am trying to finish my rational class for java and everywhere I have looked to make it finished doesn't have it near the same. I know I could use others programs that where made but the ones I have seen don't have it for where you put the input in…
-5
votes
2 answers

Rational Class Built Off of Polynomial Class: An Analysis of Class Dependency and Operator Overloading

I have a Polynomial and Rational class which manipulates polynomial and rational functions as vectors. I've defined non-member operators for *, /, +, and -, but I don't think I'm getting how to use them correctly (see code…
-7
votes
2 answers

N th term of series:0,1,3,6,10,15,21,

0,1,3,6,10,15,21,... each term gets incremented in the order of natural numbers I tried to generate the nth of the series but ended with TLE here's my code s=0 for(int i=1;i<=n;i++) s=s+(i-1); Can any anybody help me with a better algorithm.
Surya Pranav
  • 1
  • 1
  • 2
1 2 3 4 5
6