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

boost::rational - prevent default reducing (i.e. 2/2 to 1/1)?

In the boost::rational class, if I do boost::rational r(2,2); std::cout << r << std::endl; The result will be 1/1. Is there a way to keep this as 2/2 without having to write a wrapper around the rational class? Ideally, I'd like this to…
mikesol
  • 1,177
  • 1
  • 11
  • 20
1
vote
2 answers

In Clojure, how can I convert a long int to a rational?

How can I convert a long int to a rational in Clojure? That does not work: user> (class (/ 5 1)) java.long.Long
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
1
vote
2 answers

How to find the numerator and the denominator of a rational in Clojure?

How to find the numerator and the denominator of a rational in Clojure? How can I convert a rational to a pair of ints?
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
1
vote
2 answers

Trouble raising -1 to a rational fraction-based power

On my TI-84 Plus (Silver Edition), I can enter the following without error: (-1)^(1/3) = -1 I also know that entering some expressions like the following would yield a non-real -imaginary- number like: (-1)^.5 Now, my problem is with C#'s Math…
TekuConcept
  • 1,264
  • 1
  • 11
  • 21
0
votes
0 answers

Python rational number to binary converter

I made a rational number- binary converter for positive numbers, but how do I do it for rational numbers? # Python3 program to convert a # decimal number to binary number # function to convert # decimal to binary def decToBinary(n): #…
0
votes
1 answer

How to implement a Joda DateTime and Duration with fraction milliseconds

I have a requirement to implement a DateTime and Duration object that keeps track of its value using a fractional value. For all intents and purposes, these types should be equivalent to the Joda's DateTime and Duration types, except the millis not…
milin
  • 414
  • 4
  • 14
0
votes
1 answer

Compile time check that lcm(a,b) doesn't overflow

I would like to have a compile-time check that taking the least common multiple of two numbers doesn't overflow. Difficulty: regarding std::lcm, The behavior is undefined if |m|, |n|, or the least common multiple of |m| and |n| is not…
0
votes
1 answer

cannot determine truth value of Relational: symbol interval

I am trying to solve inequality using sympy symbols but I can't set an interval for my symbols, is there a way to do it??? import sympy as sy p = sy.Symbol("p") # 0 < p < 1 f = p**2-1 if f < 0: print("f is negative")
0
votes
1 answer

sympy square roots: best way to do operations on rational numbers?

Since i want square roots to be simplified, I've come across this workaround: from sympy import sqrt, factor, simplify _sqrt = sqrt sqrt = lambda x: factor(simplify(_sqrt(x))) # do maths operations with sqrt... But it's too slow and I don't think…
Amin Guermazi
  • 1,632
  • 9
  • 19
0
votes
1 answer

Java How to get 0 as denominator to show in rational class

Right now, when running my Rational program I get a 1 when creating a new rational with the numerator being 2 and denominator being 0, and my teacher wants me to replace the denominator with a 1 instead of a 0 but I am unable to and get a stack…
0
votes
0 answers

Reducing to Simple Fraction

Here, I have implemented a Nat(positive integers) data type and Sign(for all integers) datatype in Haskell and I have implemented their Plus functions respectively, which are working correctly. Now, I was thinking of extending these to rationals…
0
votes
1 answer

Why cant I use these rational, numerator & denominator from class numbers.Rational in Python 3.8?

Can someone help me in understanding how to use these rational, numerator & denominator *class numbers.Rational Subtypes Real and adds numerator and denominator properties, which should be in lowest terms. With these, it provides a default for…
0
votes
0 answers

Is there any way to describe rational numbers in flex scanner?

I want to design a parser that recognizes correctly written arithmetic expressions on rational numbers. The prepared analyzer should recognize rational numbers in the notation with a fractional dash, which consists of a numerator and denominator,…
JustPawel
  • 165
  • 1
  • 9
0
votes
1 answer

Converting rational number to string

I have the following requirements: given a rational number (x % y): If y != 1 => return "x y" Otherwise: return "x" The following function works: import Data.Ratio my_show :: (Integral a, Show a) => (Ratio a) -> String my_show rat = let x =…
user4035
  • 22,508
  • 11
  • 59
  • 94
0
votes
0 answers

Write Exif Metadata for property items with rational bits (rational64u)

I am trying to modify / write to property items that are rational. One Exif property that is rational is the Exposure Time: Information from EXIF Tags: 0x829a, ExposureTime, rational64u, ExifIFD I have however run into a roadblock and don't know…
user4743021