erikwiffin / 0.30000000000000004 Goto Github PK
View Code? Open in Web Editor NEWFloating Point Math Examples
Home Page: https://0.30000000000000004.com/
License: GNU General Public License v3.0
Floating Point Math Examples
Home Page: https://0.30000000000000004.com/
License: GNU General Public License v3.0
I would recommend adding another test that shows whether
0.1+0.2==0.3
in the various languages. One or two will get it right, but most do not, even the ones that print 0.3 when you do the addition.
The website shows "可以使用以上搜索栏查询整个网站,或者尝试以下链接。" in Chinese, which mean "You may use search bar or try the following link(s)."
Maybe you should replace or delete this hyperlink.
Hi there,
It would be good to redirect people who visited 30000000000000004.com to 0.30000000000000004.com
1> io:format("~f~n", [0.1 + 0.2]).
0.300000
ok
2> io:format("~e~n", [0.1 + 0.2]).
3.00000e-1
objective-c gone from the list of languages on website after updating examples.
Using Double
triggers the Problem in GHC, Float
works fine (could be a precision reason, though):
Prelude> 0.2 + 0.1 :: Double
0.30000000000000004
Prelude> 0.2 + 0.1 :: Float
0.3
What do you think about adding column with result of 0.1+0.2==0.3
?
C# has a decimal type that handles the addition properly.
decimal correct = 0.1m + 0.2m;
Console.WriteLine(correct);
Output:
0.3
Example: https://dotnetfiddle.net/xcsQdh
Tested on both SBCL and ECL, (+ 0.1d0 0.2d0)
does actually produce 0.30000000000000004d0
.
The link at the end of the README could be added to the repository metadata fields at the top of the page, where it would be more accessible.
A description can also be added there, which would appear in the page title in browser tabs, in search results, etc.
At least in Firefox, the longer code blocks overflow into the next column, resulting in a messy layout.
Firefox screenshot (overflow):
Chrome screenshot (scrollbars):
Possibly adding the overflow property to the td
elements would help?
The results are partially different with which in Matlab.
layout: post
title: 'GNU Octave'
code:
On .Net 4.6, Console.Writeline(0.1 + 0.2);
outputs 0.3
Your echo .1 + .2;
displays 0.3
because PHP converts it to a string in echo
first while still internally using 0.30000000000000004
. You can verify this with: echo ceil((.1 + .2) * 10);
(this prints 4
). My suggestion is to run a similar test for all languages and displaying and (if needed) explaining the results.
;; Bigdecimal support
(+ 0.1M 0.2M)
; => 0.3
;; Ratios
(+ 1/10 2/10)
;=> 3/10
There are not that many examples of this in Data Analysis Expressions (DAX),
It would be:
EVALUATE { VAR _sum = 0.1 + 0.2 // 0.30000000000000004 RETURN IF( _sum = 0.3, ":)", ":(" ) }
EVALUATE { VAR _sum = CURRENCY( 0.1 ) + CURRENCY( 0.2 ) // 0.3 RETURN IF( _sum = 0.3, ":)", ":(" ) }
In JavaScript, this library provides an “arbitrary-precision Decimal type” http://mikemcl.github.io/decimal.js/
Although the markdown source for Raku shows the correct output to raku -e 'say (0.1 + 0.2).fmt("%.17f")'
is 0.30000000000000000
, on the published website just shows the output as 0.3
.
Hey Erik Wiffin. Thanks for your initiative to build this site. Very helpful to introduce people about floating point.
Yet, the main site: http://0.30000000000000004.com/ seems down right now so i can't refer people to this site. Currently, there is no way to access this website other than from GH repo and archive.is. Could i mirror this? I don't see LICENSE file so i ask about this.
Also related to #105
A bug I filed about IEEE 754 documentation a while ago for MySQL:
https://bugs.mysql.com/bug.php?id=57519
Support for NaN differs between MySQL and PostgreSQL. I didn't see any information about the 'special' values on http://0.30000000000000004.com
Note that there are different behaviors within one database system:
http://sqlfiddle.com/#!6/12e70/3
CREATE TABLE t1 (f FLOAT);
SELECT 0.1 + 0.2;
INSERT INTO t1 VALUES(0.1),(0.2);
SELECT SUM(f) FROM t1;
With Microsoft SQL Server 2014 this has the following output:
0.3
0.30000000000000004
With MySQL 5.6:
0.3
0.30000000447034836
http://sqlfiddle.com/#!9/2e75e/1
Oracle 11gR2 returns 0.3 in both cases:
http://sqlfiddle.com/#!4/0509e6/4
Note that Oracle has FLOAT and BINARY_FLOAT
http://sqlfiddle.com/#!4/cf223/1
$ awk --version | head -1
GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)
The example indeed prints 0.3, but 0.1 + 0.2 != 0.3:
$ awk 'BEGIN { print 0.1 + 0.2 }'
0.3
$ awk 'BEGIN { print (0.1 + 0.2) == 0.3 }'
0
It's because
$ awk 'BEGIN { printf "%0.25f", 0.1 + 0.2 }'
0.3000000000000000444089210
$ awk 'BEGIN { printf "%0.25f", 0.3 }'
0.2999999999999999888977698
Perhaps this example could explain.
CREATE TABLE test
(fla
FLOAT,flb
FLOAT,dba
DOUBLE(10,2),dbb
DOUBLE(10,2));
We have a table like this:
+-------+-------------+
| Field | Type |
+-------+-------------+
| fla | float |
| flb | float |
| dba | double(10,2)|
| dbb | double(10,2)|
+-------+-------------+
For first difference, we try to insert a record with '1.2' to each field:
INSERT INTO test
values (1.2,1.2,1.2,1.2);
The table showing like this:
SELECT * FROM test
;
+------+------+------+------+
| fla | flb | dba | dbb |
+------+------+------+------+
| 1.2 | 1.2 | 1.20 | 1.20 |
+------+------+------+------+
See the difference?
We try to next example:
SELECT fla+flb, dba+dbb FROM test
;
Hola! We can find the difference like this:
+--------------------+---------+
| fla+flb | dba+dbb |
+--------------------+---------+
| 2.4000000953674316 | 2.40 |
+--------------------+---------+
The C++ example is as follows:
std::cout << setprecision(17) << 0.1 + 0.2 << std.endl;
The function setprecision()
uses the std namespace, and should therefore be written as such. Same goes for endl
. Furthermore, the C example also works in C++; perhaps these should be merged?
Is this repo published somewhere? It would be a good idea to include a link to the published website in this repos README.md
12px is much too small. I recommend leaving it at the default (normally 16px), and defining most other things in terms of ems or rems instead of pixels, and using max-width: 100%
so that the greater width isn’t causing overflow trouble unnecessarily. (Mostly you could instead change width
s to max-width
s, but some bits may need to be told to be as wide as possible within that.)
Use of the word decimals
is confusing. For example:
In binary, 1 / 2, 1 / 4, 1 / 8 would all be expressed cleanly as decimals, while 1 / 5 or 1 / 10 would be repeating decimals
Here the first-use as decimals
is correct, meaning when converted to decimal and written out, but the second-use is confusing; I think it means "digits after the binary-point". I don't think "decimals" is a good word to mean "digits after the binary-point".
I don't have a better word, just found it confusing. Please let me know if I got it all wrong. Awesome explanation though - love it :)
Seems the example is from before the stabilisation of Rust.
It should rather be something like this.
You could leverage gh-pages build to host this site and it would work with custom domain as well.
Or you could just push to gh-pages branch an have http://erikwiffin.github.io/0.30000000000000004
server as backup mirror.
If you consider switching to gh-pages with domain name, you can find instruction
This needs to be added as example as well to be fair.
This is the certificate that is presented to me when I visit https://0.30000000000000004.com/:
The public key I was presented is issued to github.com etc..., not the domain.
It would be nice if the examples were presented in a sorted alphabetical order by the first column, Language.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.