Questions tagged [fractions]

Fractions, or "fractional numbers" (lit. "broken numbers"), or "rational numbers", are numbers expressed as the ratio of two integers, such as 1/2 or 23/17.

In computing and programming, fractional (or "rational") numbers are an alternative to floating point numbers: Since numerator and denominator are stored as integers, the representation is exact, as opposed to most floating point implementations, which cannot represent most rational numbers exactly. Arbitrary-precision ("bignum") libraries usually contain support for rational numbers.

800 questions
-3
votes
1 answer

Egyptian fraction using Fibonacci's Algorithm

I have this problem in which we are trying to find an Egyptian fraction using Fibonacci's algorithm. For the numerator, it is always must be equal to one. Then, we have to determine whether the bottom is a practical number. We have 2 inputs from the…
Ang
  • 1
-3
votes
1 answer

military aptitude test fractions

I'm looking to get into the armed forces and have been practicing an online practice test. I'm having trouble with one question. I know guess and check will work but was hoping for a more effective solution. The question is: How many soldiers are…
NSaid
  • 689
  • 2
  • 16
  • 32
-3
votes
1 answer

Infinite loop when simplifying fractions in binary in C

I'm trying to simplify fractions in binary with this code that checks if the value is even: int is_even(floatlet value){ if(value & 1) return 0; return 1; } And this while loop keeps bit shifting until the value is odd.…
skaggs
  • 15
  • 4
-3
votes
2 answers

Converting decimals to fractions

I just wanted to convert a decimal to fractions in Python. I found some answers here on stackoverflow. How to convert a decimal number into fraction? I tried both the methods but they didn't worked for 1.4 as input, though they worked for…
-3
votes
5 answers

How to make this fraction addition operator work?

Fraction &operator+= (const Fraction &obj){ if (denom == obj.denom){ num += obj.num; } else{ lcm = l_c_m(num, denom); num * (lcm / denom) += obj.num * (lcm / obj.denom); } return *this; //returns current…
frag r33f
  • 35
  • 4
-3
votes
2 answers

square of square root C++

I'm doing a mixed number calculator for my c++ class. We are to store everything in a custom mixed number class with whole number, numerator and denominator. Because of this, irrational answers have to be approximated before converting to mixed…
giraid
  • 3
  • 3
-3
votes
1 answer

Fractions class in c++ explaination

Can someone just explain whats going in this code? You don't have to go line by line but a general summary would be really helpful. It's similar to other fraction class c++ code so you don't have to completely refer to this code.…
-3
votes
1 answer

Adding fractions using classes (Wrong output)

I previously wrote a program that adds two fractions together and prints the output, simple I know. I originally implemented the program using structs and now I'm trying to re-implement it using classes, not so simple i guess... The problem is…
DomBavetta
  • 13
  • 1
  • 1
  • 8
-3
votes
2 answers

Having issues with Improper Fraction output in Java

I believe I am doing this right, but I am having issues with my ImproperFraction method in my fraction class outputting properly. It is just to output wither or not the fraction is improper, doesn't have to be anything special. public boolean…
karalee
  • 3
  • 1
-3
votes
2 answers

Java Fraction Calculator error

My Homework over thanksgiving is to make a fraction calculator that takes input and gives the answer for example 1/2 + 1/4 = 3/4 but when i enter input i get the error: Error Starts: Exception in thread "main" java.lang.Error: Unresolved…
-3
votes
2 answers

What's the limit of fraction inside square root

I need to find limit sqrt((3x-1)/(x+2)) when x->infinity Can anyone help me please?
Jan Vorisek
  • 530
  • 1
  • 7
  • 17
-4
votes
1 answer

Get the simple fraction of decimal number c#

I need to get the simple fraction of a decimal number in c# Example: 1 would be 1 /1 16 would be 16 / 1 0.125 would be 1 / 8 .30769231 would be 4/13 The solution i found is this: Decimal_target= 0.1 In the numerator and denominator for the decimal…
Chris
  • 51
  • 1
  • 1
  • 10
-4
votes
1 answer

Adding Fractions (Java)

In this program, the user is asked for 4 integers that represent two fractions. First ask for the numerator of the first and then the denominator. Then ask for the numerator and denominator of the second. The program should add the two fractions and…
Joshua Wu
  • 9
  • 3
-4
votes
1 answer

Why does "double i = 1/12;" yields to i = 0?

I think the title says everything. I want to define a variable i as the fraction 1/12. However, i is 0. double i = 1/12; std::cout << i; // Output: 0 Or, more specific, I want to calculate a power of something: im_ = std::pow((1 + i), (1/12)) -…
Steve
  • 361
  • 1
  • 2
  • 6
-4
votes
3 answers

Inverting the exponent of a long double gives me an insane result

I am trying to invert the exponent of a long double. Suppose x = 3.5e1356. I want x to be 3.5e-1356. I have this code: long double x = 3.5e1356L; int exponent; long double fraction = frexpl(x, &exponent); // recreate number with an inverted…
Duck
  • 34,902
  • 47
  • 248
  • 470
1 2 3
53
54