Shivam
Np
Maxim Khromov
why i can't to compare O1 and O2?
Maxim Khromov
program don't understand that are same and skip this line
Maxim Khromov
Maxim Khromov
but when i use function printf, you can see that they are same
Dima
Maxim Khromov
Димас помоги)
Anonymous
can you send compressed imag?
olli
why i can't to compare O1 and O2?
Don't use == to compare floating point values
Maxim Khromov
what should I use?
Likai
why?
It makes rockets explode
Anonymous
Anonymous
what should I use?
== but the other way can be: fabs(f1 - f2) >= 0.000001
Anonymous
but for the most part f1 == f2 should work
Anonymous
i do not want to download your image
Anonymous
because then i have to delete it after
Anonymous
so i would prefer you send the compressed or paste the code
olli
why?
Because floating points are approximations where the order of operations matters.
Anonymous
you could also upload the file
Maxim Khromov
Likai
https://itsfoss.com/a-floating-point-error-that-caused-a-damage-worth-half-a-billion/?fsmoe=false
Anonymous
https://prnt.sc/ljmfke
the more accurate way is to find the minimal number you want
Anonymous
so lets say you want a hundredth precision that you are working with
Anonymous
then what you do is: floorf(O1 * 100) / 100;
Anonymous
so have: #include <math.h> at the top
Maxim Khromov
uff..)
Anonymous
then do O1 = roundf(O1 * 100) / 100; O2 = roundf(O2 * 100) / 100;
Anonymous
roundf is more precise then floorf
Maxim Khromov
and after that I can compare them?
Anonymous
this works on floats but since you are using doubles you might want to use round
Anonymous
yep after that you can do all the operations with no worries
Maxim Khromov
Yeees its work!!
Maxim Khromov
thank u very much 🙂
Anonymous
welcome
Anonymous
you SHOULD use == for comparision
Anonymous
but you want to set up the doubles correctly first
olli
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ https://stackoverflow.com/a/4682941/4416573 I would say comparing floats using == is okay if false-negatives are acceptable.
Anonymous
as any mathematical operation will result in accumulation of the errors
Anonymous
then do O1 = roundf(O1 * 100) / 100; O2 = roundf(O2 * 100) / 100;
if you do it this way you force the double to become more precise
Anonymous
and works with a finite set of decimals
olli
why would you say rounding makes a value more precise?!
BinaryByter
it does quite the opposite lol
Anonymous
it does quite the opposite lol
is that why scientists round for precision?
Anonymous
BinaryByter
they don't round IN ORDER TO GET precision
Anonymous
look up significant digits
BinaryByter
they round in order to show the unsure digit
BinaryByter
look up significant digits
man, can't you just stop being a meme already?
Anonymous
they round in order to show the unsure digit
no to get RID of the unsure digit
Anonymous
https://en.wikipedia.org/wiki/Significant_figures
BinaryByter
:facepalm:
Anonymous
at either case you have a double and it has a certain precision from your measurement
Anonymous
you should only be working with the max precision of your elements
olli
Okay, well it depends, if you consider precise being accurate, then no, it's not. If you mean precise in terms of "stable" then it's true
Anonymous
PRECISION IS ACCURACY
Anonymous
Accuracy and Precision: Accuracy refers to the closeness of a measured value to a standard or known value. ... Precision refers to the closeness of two or more measurements to each other. Using the example above, if you weigh a given substance five times, and get 3.2 kg each time, then your measurement is very precise. well not exactly
Diego
I'm trying to create a function that returns random int between 0 and 1, but It always returns the same values in different program executions. As you can see in this image. Any idea why is this happening?
Diego
BinaryByter
Diego
This is the code
klimi
This is the code
You don't generate seed
klimi
Look at srand()
BinaryByter
srand*
klimi
klimi
Stupid autocorrect
Diego
Ok, let me see
Diego
Solved thakns!
klimi
Oh
Anonymous
Search this c++ pdf cpluplus You will get a book that will teach basics
- Raymond
Ok I have a weird problem