Saturday, September 24, 2011

Don't test for exact equality of floating point numbers


A discussion came up on Guido von Rossum's Google Plus post. It comes down to the fact that 2.1 is not exactly represented as a floating point number. Internally it's 2.0999999999999996, and this causes unexpected behavior.

These kinds of issues often come up. The confusion is caused by treating floating point numbers as exact numbers, and expecting calculations with them to produce results meaningful down to the last bit.

People at Wolfram Research has spent a lot of effort trying to get arithmetic right, and here's what a principle kernel developer, Daniel Lichtblau, has to say about the issue of making floating point calculations deterministic:

It is not in any way "solvable", at least not by means accessible to us (which in some sense defines it as "not a problem"). Depends too much on alignment-handling vagaries of MKL libraries, ordering of operations in BLAS, and usage, or not, of extended precision registers. See also IEEE 754: a careful reading may shed light on how different results for the same computation can arise in compliant hardware/software, even on the same machine

In addition to ambiguity in IEEE 754, which gives slight differences between different floating point libraries, there's an issue of the same library giving slightly different results on reruns with same inputs and and same machine, because of run-time optimization by the processor

The solution that Wolfram Inc came up with is to treat the last 7 bits of IEEE doubles as unknown. When testing for equality, those bits are ignored. When printing a number, it chooses representation that gives a nice printout. For instance, Print[2.0999999999999996] will display 2.1

So here's the rule of thumb for IEEE 754 floating point numbers:

When checking for equality of floating point doubles, ignore the last 7 bits of the mantissa.

50 comments:

Unknown said...

Just in case you haven't seen it yet:
http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html

Unknown said...

How to load notMNIST on keras library

Anonymous said...

got 94.5% accuracy with 3 layers (all with RELU): 1024, 256, 64, applied dropout with prob=0.5

Unknown said...

nice blog
android training in bangalore
ios training in bangalore
machine learning online training

Unknown said...

useful blog
python interview questions
cognos interview questions
perl interview questions
vlsi interview questions
web api interview questions
msbi interview questions

Unknown said...

laravel interview questions
aem interview questions
salesforce interview questions
oops abab interview questions
itil interview questions
informatica interview questions
extjs interview questions

Unknown said...

sap bi interview questions
hive interview questions
seo interview questions
as400 interview questions
wordpress interview questions
accounting interview questions
basic accounting and financial interview questions

Unknown said...

People are really wanted to go with the flows and let have a perfect life while they are floating in nowhere and then this could help them out. https://www.nursingcapstone.org/nursing-student-portfolio/ will give you some amazing idea and very effective for the papers writing.

Unknown said...

While you wanted to go with the flow you need to know that not every time you should follow someon and go on. go to site that I love for the helpful information and its really amazing.

Unknown said...

People are always waited for this day. Yeah, I am talking about the new year day when people love the day and love to do new thing with new promises. https://www.writemylitreview.com/our-services/ here abut the writing tips.

Anonymous said...

Word press is a best Open Source CMS which allows it to be used free of cost. You can use it on any kind of personal or commercial website without have to pay a single penny for it. It is built on PHP/MySQL (which is again Open Source) and licensed under GPL.
wordpress interview questions

Unknown said...

You cannot just measure with the right equality when the things are really floating. Click here http://www.paschoolrequirements.com/pa-programs-in-maine/ to know about the maine program.

linda said...

We may have keep the balance on where we are working on but for that every task should be take into account. http://www.personalstatementpsychology.com/counselor-personal-statement-that-will-succeed-8-tips-to-bare-in-mind/ will help you out with some tips.

katetech said...

Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...
Internships for College Students in hyd
it internships in Hyderabad
Student Internships in Hyderabad

Unknown said...

Thank you... training institute in Jaipur

Anonymous said...

Nice Arcticle...
Machine Learning Interview Questions and Answers
Artificial Intelligence Interview Questions and Answers

bhuvi said...

aws training in bangalore

artificial intelligence training in bangalore

machine learning training in bangalore

blockchain training in bangalore

iot training in bangalore

artificial intelligence certification

artificial intelligence certification

basha said...

Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
oracle fusion financials classroom training
Workday HCM Online Training
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Oracle Fusion HCM Classroom Training

RAKSASA POKER said...

RaksasaPoker Agen Domino Server Terbaru dan BandarQ Terpercaya Indonesia
Website Judi Online Yang memberikan Pelayanan Terbaik dan mempunyai Server Yang Berkualitas Di Dalam Permainan Asli tanpa Robot Ataupun Admin Ikut Serta Bermain Serta Memberikan Kemudahan Dalam Melakukan Proses Transaksi Deposit Dan Wirthdaw Hanya 2 Menit Dana Anda Pasti Sudah Di Proses.

BandarQ

Domino99

Capsa

Agen Poker

Agen Domino99

Agen Capsa

Gabung Sekarang Juga Dan Dapatkan Ratusan Juta Bersama Kamihttps://akhsadew.blogspot.com

Yunita Puspita said...

RaksasaPoker Agen Domino Server Terbaru dan BandarQ Terpercaya Indonesia
Website Judi Online Yang memberikan Pelayanan Terbaik dan mempunyai Server Yang Berkualitas Di Dalam Permainan Asli tanpa Robot Ataupun Admin Ikut Serta Bermain Serta Memberikan Kemudahan Dalam Melakukan Proses Transaksi Deposit Dan Wirthdaw Hanya 2 Menit Dana Anda Pasti Sudah Di Proses.

BandarQ

Domino99

Capsa

Agen Poker

Agen Domino99

Agen Capsa

Gabung Sekarang Juga Dan Dapatkan Ratusan Juta Bersama Kamihttps://akhsadew.blogspot.comACaa

Avanexa Technologies said...

great blog...


BEST DIGITAL MARKETING AND WEBSITE DESIGNING COMPANY IN COIMBATORE

braincarve said...

Abacus Classes in chennai
vedic maths training chennai
abacus training classes in chennai

remo said...

THANKS FOR THE INFORMATION....
Digital Marketing Internship Program in BangaloreDigital Marketing Internship Program in Bangalore

draj said...


Excellent machine learning blog,thanks for sharing...
Seo Internship in Bangalore
Smo Internship in Bangalore
Digital Marketing Internship Program in Bangalore

Machine Learning Training in Bangalore | Machine Learning course - ICSS said...

Wonderful blog!!! the article which you have shared is informative for us.Python has been the top most powerful and flexible open source language that is really very easy to learn. In our instructor based Python Training in Bangalore Advance Level we will teach you how to use the powerful libraries for data analysis and manipulation.https://indiancybersecuritysolutions.com/python-training-in-bangalore-advance-level/

unknow said...

I really enjoyed your blog Thanks for sharing such an informative post.
https://myseokhazana.com/
https://seosagar.in/
Indian Bookmarking list
Indian Bookmarking list
India Classified Submission List
Indian Classified List
<a href="https://seosagar.in/</a>

Digitalmarketing said...

I have perused your blog its appealing, I like it your blog.
digital marketing company in chennai,
digital marketing agency in india,
digital marketing company in chennai,
online marketing company in chennai,
digital marketing company in india,
digital marketing services,
digital marketing company,

best ppc company in india said...

I have inspected your blog its associating with and essential. I like it your blog.
ppc marketing services
pay per click advertising services
ppc campaign management services
ppc marketing company
ppc management services

mobile application development said...

Amazing Post. Your blog is very inspiring. Thanks for Posting.
Mobile App Development Company in chennai
mobile app development chennai
Mobile application development company in chennai
Mobile application development chennai
Mobile apps development companies in chennai
enterprise mobile app development company

Elevators and Lifts said...
This comment has been removed by the author.
Elevators and Lifts said...

Great post. Are you looking for the best Automatic gates in India,
Then click here: Automatic gates

Angular expert said...

Very nice post. I absolutely love this site. Thanks!



Angular Training in Bangalore

Python Training in Marathahalli, Bangalore

Angular expert said...

You need to take part in a contest for one of the finest websites on the net. I will highly recommend this website!

UI Development Training in Marathahalli

Full stack Development Training in Marthahalli Bangalore


UI Development Training in Bangalore

deepika said...

very nice article and very informative information.
jquery interview questions

Kanye Co Jamila said...


Great Article
IEEE final year projects on machine learning


JavaScript Training in Chennai

Final Year Project Centers in Chennai



JavaScript Training in Chennai

iuwekjhbr said...

Please refer below if you are looking for Online Job Support and Proxy support from India


Java Online Job Support and Proxy support from India | AWS Online Job Support and Proxy Support From India | Python Online Job Support and Proxy Support From India | Angular Online Job Support from India | Android Online Job Support and Proxy Support from India

Thank you for excellent article.

iuwekjhbr said...

Please refer below if you are looking for best Online job support and proxy interview from India

DevOps Proxy Interview Support From India | PHP Proxy Interview Support From India | Selenium Proxy Interview Support From India | Hadoop Proxy Interview Support From India | Java Proxy Interview Support From India | Angular Proxy Interview Support From India | Python Proxy Interview Support From India | Android Proxy Interview Support From India

Thank you for excellent article.

Unknown said...

Please refer below if you are looking for best Online job support and proxy interview from India

AWS Proxy Interview Support From India | Workday Proxy Interview Support From India | ReactJS Proxy Interview Support From India | Manual Testing Proxy Interview Support From India | Dotnet Proxy Interview Support From India | Peoplesoft Proxy Interview Support From India | Teradata Proxy Interview Support From India

Thank you for excellent article.

mahi said...

Please refer below if you are looking for best Training center in coimbatore

Java Training in Coimbatore | Digital Marketing Training in Coimbatore | SEO Training in Coimbatore | Tally Training in Coimbatore | Python Training In Coimbatore | PMP Training In Coimbatore | Scrum Training In Coimbatore

Thank you for excellent article.

Naveen said...

Please refer below if you are looking for best Training in coimbatore

Hadoop Training in Coimbatore | CCNA Training in Coimbatore | AWS Training in Coimbatore | AngularJS Training in Coimbatore | Dotnet Training In Coimbatore | SAS Training In Coimbatore | R-Programming Training In Coimbatore

Thank you for excellent article.

Anonymous said...


Hello, o you know that the best way to boost your brain is
visiting or contacting us


https://weiiitrading.com/our-products/moonrock-carts/buy-empty-moonrock-clear-vape-cartridges-blue-carts-dr-zodiak-atomizers-with-flavor-box-packaging/

https://weiiitrading.com/our-products/heavy-hitters-carts/buy-wholesale-new-heavy-hitter-vape-cartridges-1-0ml-ceramic-coil-empty-tank-carts-510-thread-thick-oil-atomizer/

https://weiiitrading.com/our-products/juul-carts/buy-hot-empty-ceramic-pod-disassembled-cartridges-0-7ml-1-0ml-vape-pod-carts-for-vape-juul-vape-pen-start-kit-top-quality/

https://weiiitrading.com/our-products/mario-carts/buy-peaches-and-dream/

https://weiiitrading.com/our-products/heavy-hitters-carts/buy-bubba-kush-cartridge-2-2g/

https://weiiitrading.com/our-products/mario-carts/buy-thin-mint-cookies/



Pila Brass Knuckles Online for sale online,

where to buy Buy Pila Brass Knuckles Online

buy valley online cartridge

buy space candy online

buy cannabis syrup online

buy botox online

cannabis bread

uk chese

47 dank vapewhite fire og

buy moonrock



Email Us

Contact: +1 619-537-6734

Advanced Diploma in Embedded Systems said...

thanks for sharing this nice infoamtion..i really enjoyed to read your information.learn bench india is the best project center in chennai..
to know more about this
best project center in chennai
best final year project center in chennai
best final year ieee project center in chennai
best embedded project center in chennai

Day Tham My said...

Class College Education training Beauty teaching university academy lesson teacher master student spa manager skin care learn eyelash extensions tattoo spray

daythammynet
daythammynet
daythammynet
daythammynet
daythammynet
daythammynet
daythammynet
daythammynet
daythammynet

Cloudi5 said...

Thanks for sharing this stuff. It helps me a lot on while implementing my web design and web development projects.

Sudharshanglim said...

Great blog !It is best institute.Top Training institute In chennai
http://chennaitraining.in/openspan-training-in-chennai/
http://chennaitraining.in/uipath-training-in-chennai/
http://chennaitraining.in/automation-anywhere-training-in-chennai/
http://chennaitraining.in/microsoft-azure-training-in-chennai/
http://chennaitraining.in/workday-training-in-chennai/
http://chennaitraining.in/vmware-training-in-chennai/

Sudharshanglim said...

Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care
http://chennaitraining.in/creo-training-in-chennai/
http://chennaitraining.in/building-estimation-and-costing-training-in-chennai/
http://chennaitraining.in/machine-learning-training-in-chennai/
http://chennaitraining.in/data-science-training-in-chennai/
http://chennaitraining.in/rpa-training-in-chennai/
http://chennaitraining.in/blueprism-training-in-chennai/

Digital Marketing in Coimbatore said...

Super Post thanks for valuable post
https://www.avavaventures.com/contact/

Offshore Web Development Company India said...

This is awesome information, Thank you for this!

75 Farm Cannabis Specialists MARLEY NATURAL said...

we have a wide range of medical signatures
just take a sec and visit us with or without prescription, and you shall be served accordingly
Buy Promethazine codeine online
Order Biotropin Online
Order Adderrall Online Without Prescription
Buy sibutramine online
buy Nembutal sodium online


buy dexedrine online
buy vyvanse online
buy methadone online
buy Nembutal sodium online
buy opana online
buy cheap ambien online
buy max performer sex pills
buy anavar online

buy amytal sodium online
buy cheap ambien
buy ephedrine crystals
fentanyl actiq
fentanyl patches


buy amytal sodium online
changa
mdma pills
buy changa dmt online
buy morning glory seeds
buy ibogaine
Ayahuasca
buy mescaline
buy Penis envy
Penis envy mushrooms
Golden teacher mushrooms
mescaline drug for sale
buy liberty cap mushrooms
liquid lsd
buy lsd liquid
what is dmt
what is lsd
buy albino penis envy
what is penis envy
buy kratom near me
buy kratom powder
buy kratom
buy liquid lsd online
buy dmt online
buy pills online
changa dmt
penis envy mushrooms
lsd for sale
dmt trip
ayahuasca tea
kentucky ayahuasca tea
iboga
ecstacy
molly




Email Us

Wickr: walkerpeac

sathishkumar said...

python training in bangalore | python online training
aws training in Bangalore | aws online training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
data science training in bangalore | data science online training