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

  • SEARCH
  • Home
  • 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 6895825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:57:29+00:00 2026-05-27T06:57:29+00:00

In Ruby (1.9), are numbers always considered exact? I know Ruby does some fairly

  • 0

In Ruby (1.9), are numbers always considered exact? I know Ruby does some fairly complex stuff with numbers under the hood, since you can do crazy things like ask for 1 trillion to the power of 1 trillion and you will get an answer (after waiting many moons for it to compute).

In Scheme, part of the specification dictates that implementations should indicate whether or not the implementation’s internal representation of the number is “exact” or not. For example, 1/2 is always exact, 1/3 is exact, 0.3333 is exact etc etc. But the result of an imprecise mathematical operation on an exact number may produce a number that the Scheme implementation knows to be inexact (due to floating point precision).

(exact? (/ 0.33333 2))
=> #f

That’s false, so it’s not exact.

Is there a way to deduce the same information in Ruby? If I always use the Complex (or Rational) representation of a number during mathematical operations, will it always be exact in Ruby, or just extremely close to exact?

Complex("0.33333") / 2

Is that exact, or not?

  • 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-05-27T06:57:30+00:00Added an answer on May 27, 2026 at 6:57 am

    Ruby’s class Float is not exact. Class Integer on the other hand more or less “is” since it shifts seamlessly from Fixnum to Bignum

    >> 1.4534346345235236346363574564356435
    => 1.45343463452352
    >> 10**400
    => 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    >> 10.0**400
    => Infinity
    

    It looks like others would love to see the test you are asking about, namely Numeric#exact? — see this feature request.

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

Sidebar

Related Questions

I need to generate a list of sequential numbers. I know Ruby you can
I know how to do it in Ruby, converting a range of numbers to
Ruby can add methods to the Number class and other core types to get
In Ruby language, how can I get the number of lines in a string?
How do I create a Ruby function that does not have an explicit number
I am new to Ruby and has always used String.scan to search for the
As i understand when we add two numbers in ruby a '+' method is
In Ruby, given an array-of-arrays representing a 2D grid of numbers, how would you
Possible Duplicate: Sort strings and numbers in Ruby I have an array of place
I need to generate the combinations of numbers using ruby. For Example : arr

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.