Float is float [Software]

posted by PharmCat  – Russia, 2020-12-18 20:53 (608 d 00:15 ago) – Posting: # 22150
Views: 5,929

(edited by PharmCat on 2020-12-18 22:02)

Hi all,

This is very trivial story... let's take

a = 0.1

next float is:

julia> nextfloat(0.1)
0.10000000000000002


so

julia> nextfloat(0.1) - 0.1
1.3877787807814457e-17


float numbers is discrete... you can't use 0.10000000000000001 ...

you can use rational numbers:

julia> 5//10 - 4//10 - 1//10 == -4//10 - 1//10 + 5//10
true


or some packages for working with big decimals

julia> using Decimals
julia> decimal(0.5)-decimal(0.4)-decimal(0.1) == decimal(-0.4)-decimal(0.1)+decimal(0.5)
true


I think in R it can be done... and never use Excel for cacl...

edit: or you can do float(big(1//10)) if you just need more precision...

edit2:

» which is just “noise”

you should be very careful with eps() because this is not an indicator of accuracy

you can use something like:

a = 1e-70
b = 2e-70
b - a


end it will work fine, problems begans whe you do somesing like: 2.0 + 1e-70 , but you can still use 2.0 * 1e-70 without problems ...

make sure not to sum numbers with difference in eps() times ...

for comparation

all.equal(target, current, tolerance = sqrt(.Machine$double.eps))

can be used, but for small numbers you should adjust tolerance

Complete thread:

UA Flag
Activity
 Admin contact
22,305 posts in 4,668 threads, 1,587 registered users;
online 9 (0 registered, 9 guests [including 7 identified bots]).
Forum time: Thursday 22:08 CEST (Europe/Vienna)

On two occasions I have been asked,—“Pray, Mr. Babbage,
if you put into the machine wrong figures,…
will the right answers come out?”
 …
I am not able rightly to apprehend the kind of confusion of ideas
that could provoke such a question.    Charles Babbage

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5