Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:45:03+00:00 2026-06-04T14:45:03+00:00

I know this is a bit hypothetical but I am wondering why no language

  • 0

I know this is a bit hypothetical but I am wondering why no language I know does it.

For example, you want to store 1/3. Give the programmer an option to specify it as 1/3, and store 1 and 3. Something like

struct float {
    int numerator;
    int denominator;
};

Rational number arithmetic becomes really easy and considerably more accurate!

This would solve so many problems related to the precision and storage limitations of floating point numbers, and I dont see it introducing any new problems as well!

Hence my question: Why aren’t rational numbers implemented and stored as fractions with zero loss of information?


As Joe asked, and others might also point out, I do not mean this to replace existing system, but to complement it.

Q: How do you store pi?

A: So many times, I am just storing 1/3 and not pi. pi can be stored the old way, and 1/3 in the new way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:45:04+00:00Added an answer on June 4, 2026 at 2:45 pm

    The reason they are not stored this way by default is that the range of valid values that can fit in a fixed set of bits is smaller. Your float class can store numbers between 1/MAXINT and MAXINT (plus or minus). A C/C++ float can represent numbers between 1E+37 and 1E-37 (plus or minus). In other words, a standard float can represent values 26 orders of magnitude bigger and 26 orders of magnitude smaller then yours despite taking half the number of bits. In general, it’s more convenient to be able to represent very large and very small values than to be perfectly precise. This is especially true since rounding tends to give us the right answers with small fractions like 1/3. In g++, the following gives 1:

    std::cout << ((1.0/3.0) * 3.0) << std::endl; 
    

    Remember that types in C++ have a fixed size in bits. Thus a datatype in 32 bits has at most MAX_UINT values. If you change the way it is represented, you’re just changing which values can be precisely represented, not increasing them. You can’t cram more in, and thus can’t be “more precise”. You trade being able to represent 1/3 precisely for not being able to represent other values precisely, like 5.4235E+25.

    It is true that your float can represent values more precisely between 1E-9 and 1E+9 (assuming 32 bit ints) but at a cost of being completely unable to represent values outside of this range. Worse, while the standard float always has 6 digits of precision, your float would have precision that varied depending on how close to zero the values were. (And note that you are using twice the bits that float does.)

    (I’m assuming 32 bit ints. Same argument applies for 64 bit ints.)

    Edit: Also note that most data people use floats for is not precise anyway. If you are reading data off of a sensor, you’ve already got imprecision, so being about to “perfectly” represent the value is pointless. If you are using a float in any sort of computing context, it’s not going to matter. There is no point in perfectly describing ‘1/3’ if your purpose is to display a bit of text 1/3rd of the way across the screen.

    The only people who really need perfect precision are mathematicians, and they generally have software that gives them this. Very few others need precision beyond what double gives.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a bit bleeding edge, but here's the question anyway: Given
I know this is a bit generic, but I'm sure you'll understand my explanation.
I know this topic is bit old, but i did surf the web and
I know this might be a bit awkward but I am trying to modify
What does this bit of code represent? I know it's some kind of if
I know this has a stupid solution but, sorry, I'm little bit confused. I
This might sound a bit of an odd question but I know what I
I know this is a little bit hypothetical, because I am not looping this,
I know this is bit of a strange one but if anyone had any
I don't know what this means, but with this bit of XAML in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.