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 5994175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:46:51+00:00 2026-05-22T23:46:51+00:00

the 3rd of the following tests fails: specify { (0.6*2).should eql(1.2) } specify {

  • 0

the 3rd of the following tests fails:

  specify { (0.6*2).should eql(1.2) }
  specify { (0.3*3).should eql(0.3*3) }
  specify { (0.3*3).should eql(0.9) } # this one fails

Why is that? Is this a floating point issue or a ruby or rspec issue?

  • 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-22T23:46:52+00:00Added an answer on May 22, 2026 at 11:46 pm

    Don’t compare floating point numbers for equality

    The problem is that neither 0.3 nor 0.9 has an exact representation1 in the floating point format, and so when multiplying 0.3 * 3 you get a number that is very, very close to 0.9, and which will round to 0.9 for printing, but it isn’t 0.9.

    And your 0.9 constant is also not precisely 0.9, and the two numbers are very slightly different.

    Using exact equality comparisons for floating point numbers is usually a mistake in any language.


    1. All integers up to about 252 have exact FP representations, but the fractions are composed of a sequence of 1 / 2n terms. Most decimal string fractions repeat in base 2.

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

Sidebar

Related Questions

I have a 3rd party struct that is comprised of the following: [StructLayout(LayoutKind.Sequential, Size=1)]
A 3rd party web application has a cross-scripting security issue. There is one page
I have the following code that downloads an object from a 3rd party and
I have following seed input data: Payperiod start: Dec 3rd Payperiod end: Dec 16
I recently ran across some 3rd party C# code which does the following: public
Background: In some PHP code dealing with a 3rd party web-service, the following code
I am learning Python, following a book (Python Programming for the Absolute Beginner, 3rd
So I've started to layout unit tests for the following bit of code: public
I have the following markup: <div id=div-1>1st div</div> <div id=div-2>2nd div</div> <div id=div-3>3rd div</div>
We use a 3rd party mixed mode assembly that interfaces with a printer device.

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.