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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:54:04+00:00 2026-05-24T06:54:04+00:00

Upon checking Float.compare(f1,f2) I found that it compares f1f2 and returns -1,0,1. Then it

  • 0

Upon checking Float.compare(f1,f2) I found that it compares f1f2
and returns -1,0,1.

Then it returns -1,0,1 if the values are -0.0, 0.0 or NAN.
What does that mean -0.0?

I would have expected something like

 return (Math.abs(f1 - f2) - 0.001f) > 0) 

where 0.001 is a given epsilon value.
Thanks.

  • 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-24T06:54:04+00:00Added an answer on May 24, 2026 at 6:54 am

    -0.0 is the negative zero, as specified by the IEEE 754 standard.

    If you’re curious about how such a value might arise, the following article does a good job of explaining it: http://www.savrola.com/resources/negative_zero.html

    As to not taking an epsilon value, this is how Float.compare is designed work (it’s an exact comparison, not an approximate one). There’s nothing to stop you from having another comparison function that does take an epsilon and does perform an approximate comparison.

    Both exact and approximate comparisons of floating-point numbers have their uses.

    As to your actual code, it suffers from a number of issues:

    1. it isn’t a three-way comparison like Float.compare;
    2. it doesn’t handle NaNs;
    3. it is generally better to specify the epsilon as a relative value, not as an absolute one, so that it scales with f1 and f2 (see this article for a discussion).

    My point here isn’t to criticise your code but to show that writing good floating-point code is harder than it first looks.

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

Sidebar

Related Questions

I'm wondering how to go about checking that a method returns a container encapsulating
Upon a click on an IMG, I would like to get to the next
Upon AD Import for SharePoint, MOSS does this automatically: Office SharePoint Server 2007 automatically
Upon reviewing a bunch of MVC style web applications, I'm noticing that it's common
Upon some research I found two functions in MATLAB to do the task: cvpartition
I got this error upon checking the php_mssql extension on my wamp server: Could
The fields I'm checking for upon registration: if($username&&$email&&$password&&$repeatpassword) { } I have about 10
Does anybody know of a good Jquery solution to checking for swear words when
I know, type checking function arguments is generally frowned upon in Python, but I
I have a set of animations that need to operate sequentially with various checking

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.