Skip to content
0:00 / 0:00

#floatingpoint#ieee754#binary

Floating Point Numbers - Computerphile

Computerphile

2.6M subscribers • 66 videos on Hallway

YouTube
  • Recommended by 2 people: 2 on Hacker News.
  • Presented by Tom Scott

Beginner. No background in the topic needed.

2.5M views12 years ago2 recommendations

Computer scienceSystems programmingMath for programmers

Tom Scott explains how floating point numbers work in computers and why they are unsuitable for handling currency.

Why can't floating point do money? It's a brilliant solution for speed of calculations in the computer, but how and why does moving the decimal point (well, in this case binary or radix point) help and how does it get currency so wrong? 3D Graphics Playlist: youtube.com/playlist?list=PLzH6n4zXuckrPkEUK5iMQrQyvj9Z6WCrm The Trouble with Timezones: youtu.be/-5wpm-gesOY More from Tom Scott: youtube.com/user/enyay and twitter.com/tomscott facebook.com/computerphile twitter.com/computer_phile This video was filmed and edited by Sean Riley. Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: bit.ly/bradychannels

Why it's here

2 people recommend this

What people say. Recommended as a simple and accessible explanation of floating point representation and its limitations with currency.

felipesabinoon Hacker News • Recommends

On “0.30000000000000004”

Recommended: Floating Point Numbers - Computerphile link to this video Tom Scott's fun and simple take on Floating Points is a good video explaining why such weird errors happen

microwavecameraon Hacker News • Recommends

On “Why do programming languages suck at math?”

Short answer, no decimal in binary and math is hard. :) Here's a couple handy videos explaining it: link to this video link

Eric Leschinskion Stack Overflow • Mentions

On “How do I print a double value without scientific notation using Java?”

Java prevent E notation in a double: Five different ways to convert a double to a normal number: import java.math.BigDecimal; import java.text.DecimalFormat; public class Runner { public static void main(String[] args) { double myvalue = 0.00000021d; //Option 1 Print bare double. System.out.println(myvalue); //Option2, use decimalFormat. DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(8); System.out.println(df.format(myvalue)); //Option 3, use printf. System.out.printf("%.9f", myvalue); System.out.println(); //Option 4, convert toBigDecimal and ask for toPlainString(). System.out.print(new BigDecimal(myvalue).toPlainString()); System.out.println…

u/mikaelhgin r/Kotlin • Mentions

On “Iterating ove float array goes wrong.”

link to this video ### Floating Point Numbers - Computerphile

u/Drach88in r/C_Programming • Mentions

On “DIVISION ERROR?? So I just printed n to show y'all that n is 2.0000 but when divided by 0.1 the answer is not 2? Please help”

Floating point arithmetic is inherently imprecise and should *never* be used for calculations where precision is essential. When working with currencies, best practice is to choose the smallest division you want to support, and simply use ints. So, if you want your smallest division to be a cent, for example, a dollar would be 100, a quarter would be 25 etc. Floats are bad... (for many applications) and you'd be doing yourself a disservice if you don't learn *conceptually* what's wrong with them. Watch this. link to this video

u/StenSoftin r/C_Programming • Mentions

On “return only till specified number of decimal places”

`double` is a floating-point number, it has no notion of decimal places (it's a binary number, not a decimal number). How many decimal places someone shows is decided when the number is formatted to a string, e.g. with `%.2f`. Btw. are you by any chance trying to use it for currency? That's not a good idea due to rounding errors, use `int` for cents instead.

mercxryon Hacker News • Mentions

On “Why you should probably be using SQLite”

You should still not use MONEY in Postgres, even their own website says so 1. I still wouldn't use floats/numerics/decimals to store currency either in any db generally, as said by others you're going to end up with inaccurate numbers 2. Therefore using integers is in fact very good for this use-case, especially if you are in accounting or book-keeping! Source: I work for a Fintech company that processes millions of payments. 1 link 2 link to this video

u/gardynain r/C_Programming • Mentions

On “Question about float precision”

welcome to the wonderful world of floating point. this video explains the problem you are encountering quite well. for tips on how to solve this you can do either of two things: * use double instead of float ( that should give you enough precision, if not I think long double was was a thing ) * create a struct and function library similar to BIGINT but for float ( I asume that's not a rabbit hole you want to go down but if you do then here is a BIGINT implementation that might help you get the idea

u/FelixGaussin r/compsci • Mentions

On “Why do we need to use a negative exponent power of 2 to represent a decimal?”

Computerphile did a link to this video on this.

u/djsteffeyin r/C_Programming • Mentions

On “[n00b] Why is the float failing at a certain point?”

best explanation for this [video