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?
BinaryByter
Anonymous
Maxim Khromov
what should I use?
BinaryByter
Likai
why?
It makes rockets explode
Anonymous
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
olli
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
Anonymous
as any mathematical operation will result in accumulation of the errors
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
olli
BinaryByter
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
Anonymous
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
klimi
BinaryByter
klimi
Diego
klimi
You don't generate seed
klimi
Look at srand()
BinaryByter
srand*
klimi
klimi
Stupid autocorrect
Diego
Ok, let me see
Diego
Solved thakns!
klimi
klimi
Oh
Anonymous
Search this
c++ pdf cpluplus
You will get a book that will teach basics
- Raymond
Ok I have a weird problem