Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Eela6
May 25, 2007
Shredded Hen
By the way, you shouldn't store currency in floats.

Adbot
ADBOT LOVES YOU

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Thermopyle posted:

This thread has always been open to beginners. The poster who has been asking questions is obviously a beginner. Floating point stuff obviously is weird to beginners.

As it should be (open to beginners). My issues was not with him, it was with the guy who thinks an acceptable answer is there's something wrong with you if you think you have to worry about the 64th decimal place, and the guy who thinks theres something wrong with needing to know arcane implementation details.

Some of us work on projects where we do care about the 64th decimal place and we do care about messy internals.

Eela6 posted:

As a note, the fact that approximate equality is often useful when comparing floats comes up often enough that isclose was added to the math and cmath modules in Python 3.5.

Python code:
In [13]: from math import isclose
    ...: isclose(.3/3, .1)
    ...:
Out[13]: True

It's also in Numpy if you're not on Python 3

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Nippashish posted:

Floating point weirdness is also one of those topics that programmers love to expand on at length when it comes up (I'm slightly surprised no one has warned you about storing currency in floats yet) and my suggestion to "not worry about it" should be taken in the context of your post triggering a page of responses. The fact that you went away from the discussion with the impression that you should "watch out" when using floats is exactly what I was trying to mitigate.

But you should worry about it though? To the point that you're aware that there are some basic pitfalls, and then keep them in mind when you're using floats. The poster you're replying to was already not worrying about it, that's why they hit a problem and had no idea what was going wrong

I mean yeah, the other extreme is the 'you can't trust floats' one, where people pretend they're full of gremlins adding random inaccuracy when your back is turned, but that's not the same as being wary and knowing what does and doesn't work

FAT32 SHAMER
Aug 16, 2012



Eela6 posted:

By the way, you shouldn't store currency in floats.

I'm assuming that you should use doubles but please expand on this

QuarkJets
Sep 8, 2008

KernelSlanders posted:

As it should be (open to beginners). My issues was not with him, it was with the guy who thinks an acceptable answer is there's something wrong with you if you think you have to worry about the 64th decimal place, and the guy who thinks theres something wrong with needing to know arcane implementation details.

Some of us work on projects where we do care about the 64th decimal place and we do care about messy internals.

Nippashish is not saying either of those things. He gave an extremely reasonable rule of thumb for how to think of floats and suggested that most people don't have to read the Floating Point Arithmetic chapter of a CS textbook just to use floats effectively

Eela6
May 25, 2007
Shredded Hen

baka kaba posted:

I mean yeah, the other extreme is the 'you can't trust floats' one, where people pretend they're full of gremlins adding random inaccuracy when your back is turned, but that's not the same as being wary and knowing what does and doesn't work

You can't trust them, though. They seem to stay still when your back is turned, but I can feel the heat of their hideous eyes. Watching. Waiting. Ready to pounce. They may not be Real, but their claws are sharp enough.

funny Star Wars parody posted:

I'm assuming that you should use doubles but please expand on this

Stack Overflow has a reasonable answer. You should not use doubles - you should use Decimals. To quote the relevant part:

Zneak from Stack Overflow posted:

The problem with floats and doubles is that the vast majority of money-like numbers don't have an exact representation as a integer times a power of two. In fact, the only fractions of a hundred between 0/100 and 100/100 (which are significant when dealing with money because they're integer cents) that can be represented exactly as an IEEE-754 binary floating-point number are 0, 0.25, 0.5, 0.75 and 1. All the others are off by a small amount.

Representing money as a double or float will probably look good at first as the software rounds off the tiny errors, but as you perform more additions, subtractions, multiplications and divisions on inexact numbers, you'll lose more and more precision as the errors add up. This makes floats and doubles inadequate for dealing with money, where perfect accuracy for multiples of base 10 powers is required.

I mostly posted the point about currency to tweak Nippanish's nose, but I'm actually glad I did. More people should know.

Eela6 fucked around with this message at 21:19 on Jun 11, 2017

QuarkJets
Sep 8, 2008

funny Star Wars parody posted:

I'm assuming that you should use doubles but please expand on this

Back when bitcoin was still newer a bunch of people learned first-hand that floating-point arithmetic has precision issues.

Say I have $2 in my account and I deposit an additional $0.10 cents. Because my financial software is bad and written by someone with almost no coding experience, now my account balance reads $2.09 (in memory it reads as 2.099999....). But even if your website is smarter than that and chooses to round up, these precision errors will slowly accumulate over time and the balance will be different than if someone had gone through with a calculator and tried to calculate the balance by hand.

Similar example, compound interest calculations are performed repeatedly and can result in numerous floating point errors compounding into a significant deviation between what's reported in the account and what should actually be in the account.

Nippashish
Nov 2, 2005

Let me see you dance!

baka kaba posted:

But you should worry about it though? To the point that you're aware that there are some basic pitfalls, and then keep them in mind when you're using floats. The poster you're replying to was already not worrying about it, that's why they hit a problem and had no idea what was going wrong

My stance is that you should be aware floats are not reals, and but you should also not worry about it. The poster I was replying to was not aware of this (and they got lots of explanations in this thread, so that part worked out well).

Nippashish
Nov 2, 2005

Let me see you dance!

Eela6 posted:

I mostly posted the point about currency to tweak Nippanish's nose, but I'm actually glad I did. More people should know.

I used to write modelling software for an insurance company and we did 100% of our currency calculations with floats. I hope this annoys you :kimchi:.

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

KernelSlanders posted:

the guy who thinks theres something wrong with needing to know arcane implementation details.

Some of us work on projects where we do care about the 64th decimal place and we do care about messy internals.

i was making a joke about the guy psyducking at a beginner who asked a question about how numbers work. i am positively thrilled about your non-web-dev coding challenges and wish you well

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Cingulate posted:

Python is a language that's being used by people with very little CS knowledge (e.g., me). That's, from what I can tell, by design: Python is easy to learn, easy to read, welcoming and forgiving. I think the thread has a good track record of being exactly like that, too.

Nippashish posted:

That's why I'm suggesting a very simple mental model that is intuitive and also sufficient for even non-beginners. Teaching people that floating point numbers are dark and spooky and complicated isn't very productive, because very few people need to care about that level of detail.

I'm responding to "Numerical Analysis is not an easy subject and it frustrates me when people pretend it's simple & intuitive" by pointing out that for most practical purposes it can be made to be exactly that.

Actually this is the worst possible takeaway because Numerical analysis is a) hard and b) for even most practical purposes requires an understanding of when it'll fail on you. Catastrophic cancellation and loss of precision can lead to cases where your component will fail and fail hard. Unless you don't want to engineer robustly, sure you can ignore it. I have run into many cases where poor or no understanding of float approximations have lead to pernicious bugs in production systems costing lots of money

While I don't expect people to understand IEEE-754 the standard in its entirety, it is immensely unhelpful to present it as a real number/exact fraction abstraction since it's leakier than a sieve (but designed in such a way to be useful for those in the know) and frequently beginners will smash their heads against the wall for days until they are told how the semantics of floats work when they run into "random" "non-deterministic" errors that are 100% deterministic.


For example, addition is commutative but not associative. This isn't trivial nor particularly expected.






funny Star Wars parody posted:

I'm assuming that you should use doubles but please expand on this
>>> 1e16 + 1 == 1e16
True

A way of salami slicing

Perfectly fine if your algorithms are insensitive to things like that (i use floats in quant finance optimization models) but try simulating a chaotic system and watch as floats are completely useless

It gets better when you have no idea how chaotic your system is!

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

LochNessMonster posted:

As the root cause of this discussion as well as a beginner in terms of programming I can tell you that you're over simplifying things.

Before this discussion I had no clue that floats would give irregular results. I was trying to do some really basic math functions and they were off by 10-20%.

If I'm running into that in my 2nd project with basic funtionality I'd say it's defintely something almost everyone will care about rather sooner than later.

I'd rather have people tell me I should watch out with where I'm using floats (like they did, thank you) than tell me not to worry because I don't need to care about that level of detail.

Floats are 100% deterministic. They will do 100% of what you tell them to do, but that's a pretty complex operation involving rescales and possibly higher precision intermediaries.

If you are calculating mathematical functions, use a library or look up a numerically stable algorithm.

QuarkJets
Sep 8, 2008

Malcolm XML posted:

Actually this is the worst possible takeaway because Numerical analysis is a) hard and b) for even most practical purposes requires an understanding of when it'll fail on you. Catastrophic cancellation and loss of precision can lead to cases where your component will fail and fail hard. Unless you don't want to engineer robustly, sure you can ignore it. I have run into many cases where poor or no understanding of float approximations have lead to pernicious bugs in production systems costing lots of money

While I don't expect people to understand IEEE-754 the standard in its entirety, it is immensely unhelpful to present it as a real number/exact fraction abstraction since it's leakier than a sieve (but designed in such a way to be useful for those in the know) and frequently beginners will smash their heads against the wall for days until they are told how the semantics of floats work when they run into "random" "non-deterministic" errors that are 100% deterministic.


For example, addition is commutative but not associative. This isn't trivial nor particularly expected.

>>> 1e16 + 1 == 1e16
True

A way of salami slicing

Perfectly fine if your algorithms are insensitive to things like that (i use floats in quant finance optimization models) but try simulating a chaotic system and watch as floats are completely useless

It gets better when you have no idea how chaotic your system is!


Malcolm XML posted:

Floats are 100% deterministic. They will do 100% of what you tell them to do, but that's a pretty complex operation involving rescales and possibly higher precision intermediaries.

If you are calculating mathematical functions, use a library or look up a numerically stable algorithm.

This is the level of worrying that Nippashish said a newbie shouldn't be at, and he was 100% right. "Why is this single line of floating-point arithmetic giving me a funny-looking answer" requires a very basic understanding of the issue, not "read this essay on the difficult subject of numerical analysis"

QuarkJets fucked around with this message at 21:58 on Jun 11, 2017

Nippashish
Nov 2, 2005

Let me see you dance!

QuarkJets posted:

This is the level of worrying that Nippashish said a newbie shouldn't be at, and he was 100% right. "Why is this single line of floating-point arithmetic giving me a funny-looking answer" requires a very basic understanding of the issue, not "read this essay on the difficult subject of numerical analysis"

I'd actually go further and say that it's not just beginners, but most programmers. If you need to worry about the details of floating point numbers then you are doing something quite unusual.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

On the other hand, if those tiny floating point inaccuracies are leading to your results being 10% out, you definitely need to know what's up

SurgicalOntologist
Jun 17, 2004

Malcolm XML posted:

Perfectly fine if your algorithms are insensitive to things like that (i use floats in quant finance optimization models) but try simulating a chaotic system and watch as floats are completely useless

It gets better when you have no idea how chaotic your system is!

Umm I simulate chaotic systems... what should I be using if not floats?

LochNessMonster
Feb 3, 2005

I need about three fitty


Nippashish posted:


Floating point weirdness is also one of those topics that programmers love to expand on at length when it comes up (I'm slightly surprised no one has warned you about storing currency in floats yet) and my suggestion to "not worry about it" should be taken in the context of your post triggering a page of responses. The fact that you went away from the discussion with the impression that you should "watch out" when using floats is exactly what I was trying to mitigate.

Well, I was not worrying about them until I found some behaviour I couldn't figure out :)

I'll read up op on the subject to see what kind of pitfalls I have to look out for.

Nippashish posted:

I'd actually go further and say that it's not just beginners, but most programmers. If you need to worry about the details of floating point numbers then you are doing something quite unusual.

I thought I had a pretty easy use case: figuring out how long and on which intervals my script should run.

Is that an unusual way to calculate it, and if so what would a regular way of solving that be?

pmchem
Jan 22, 2010


Nippashish posted:

I'd actually go further and say that it's not just beginners, but most programmers. If you need to worry about the details of floating point numbers then you are doing something quite unusual.

Nah, floating point correctness and approximations come up all the time in scientific computing, especially if you have unit tests. Scientific computing isn't "quite unusual"; it's the primary driver for the biggest floating-point computers in the world: https://www.top500.org/lists/2016/11/

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

SurgicalOntologist posted:

Umm I simulate chaotic systems... what should I be using if not floats?

a complicated algorithm that compensates for the fact that the system is very sensitive to accumulated approximation error and a lot of whiskey when b/c even then long term behavior is sketchy


Nippashish posted:

I'd actually go further and say that it's not just beginners, but most programmers. If you need to worry about the details of floating point numbers then you are doing something quite unusual.

any programmer that's using floats for numerical work needs to know when and how they work so when they gently caress up they aren't surprised. math.fsum is in the standard library for a reason

Better to learn this now than with actual repercussions on the line


QuarkJets posted:

This is the level of worrying that Nippashish said a newbie shouldn't be at, and he was 100% right. "Why is this single line of floating-point arithmetic giving me a funny-looking answer" requires a very basic understanding of the issue, not "read this essay on the difficult subject of numerical analysis"

Newbies shouldn't worry about how to use lathes, just have them lose a finger or break a few thousand parts instead of having them learn how to use their tools

Nippashish
Nov 2, 2005

Let me see you dance!

pmchem posted:

Nah, floating point correctness and approximations come up all the time in scientific computing, especially if you have unit tests. Scientific computing isn't "quite unusual"; it's the primary driver for the biggest floating-point computers in the world: https://www.top500.org/lists/2016/11/

I'm well aware of this, pushing floats around is my day job. Most of the careful thinking about stability is done in at the level of BLAS and friends and very few people actually write that kind of code (the few that do do need to care about the details of floats).

When you're writing scientific software your reasoning about stability typically happens at a higher level of abstraction than the properties of floats. Instead you think about the properties of matrix factorizations and DE solvers and other high level operations (which inherit their properties from floats, but not in ways you control). Reasoning at the boundary is dominated by "things can get weird with really big or really small numbers", which I why I suggested that as a mental model earlier.

QuarkJets
Sep 8, 2008

Malcolm XML posted:

Newbies shouldn't worry about how to use lathes, just have them lose a finger or break a few thousand parts instead of having them learn how to use their tools

Is writing bad analogies required for numerical analysis, now?

You're seriously fighting for the position that says "a person new to programming has to have a solid understanding of the difficult topic of numerical analysis before writing a program that uses floats". Is that really the hill that you want to die on?

Eela6
May 25, 2007
Shredded Hen
I am on that side. That said, I learned how to program in a numerical analysis class, so I recognize I am a bit of an outlier here.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

LochNessMonster posted:

I thought I had a pretty easy use case: figuring out how long and on which intervals my script should run.

Is that an unusual way to calculate it, and if so what would a regular way of solving that be?

There's nothing wrong with what you were doing (and the results you were printing were still correct to a very high accuracy) - you just need to be aware that you might get some awkward numbers. Really what you needed to do was format your print output to a fixed number of decimal places, that's all, same as you would if you were doing some awkward division where you knew the answer would be like 7.4042780206425627001183

For other stuff, it really depends. If you're doing a test and you want to compare a result to an expected answer, and that answer is the result of a particular calculation (like a ratio), you can perform that calculation and compare to that instead of the literal result you expect. That way your expected answer will have the same error as the actual answer (because they represent the same floating point calculation) and they'll be equal

If your expected answer is a little harder to express, and you want to just say what the value you expect is, accept that the actual answer might not be exactly what you're looking for, but within a certain tolerance - like a real-world measurement. Usually in that case you'd specify an acceptable error amount and make sure the difference between the expected and actual answers doesn't exceed that

There's a python section on this stuff and it gives you some handy ways to deal with all these things

pmchem
Jan 22, 2010


Nippashish posted:

I'm well aware of this, pushing floats around is my day job.

Cool, mine too. You ignored the point about unit tests in my post. If you write scientific software that has numerical tests of floating point results, then as I'm sure you're aware, when you change (compiler / compiler flags / arch / libraries), the float results may slightly change. That's a pretty common occurrence, and is a reason why anyone involved with scientific software should be aware of floats. Not unusual at all.

Cingulate
Oct 23, 2012

by Fluffdaddy

Malcolm XML posted:

any programmer that's using floats for numerical work needs to know when and how they work so when they gently caress up they aren't surprised. math.fsum is in the standard library for a reason

pmchem posted:

anyone involved with scientific software should be aware of floats

I would think the entire neural network community largely ignores floating point issues, what with them running near-exclusively on single precision.

Malcolm XML posted:

Actually this is the worst possible takeaway because Numerical analysis is a) hard and b) for even most practical purposes requires an understanding of when it'll fail on you. Catastrophic cancellation and loss of precision can lead to cases where your component will fail and fail hard. Unless you don't want to engineer robustly, sure you can ignore it. I have run into many cases where poor or no understanding of float approximations have lead to pernicious bugs in production systems costing lots of money

While I don't expect people to understand IEEE-754 the standard in its entirety, it is immensely unhelpful to present it as a real number/exact fraction abstraction since it's leakier than a sieve (but designed in such a way to be useful for those in the know) and frequently beginners will smash their heads against the wall for days until they are told how the semantics of floats work when they run into "random" "non-deterministic" errors that are 100% deterministic.


For example, addition is commutative but not associative. This isn't trivial nor particularly expected.

>>> 1e16 + 1 == 1e16
True

A way of salami slicing

Perfectly fine if your algorithms are insensitive to things like that (i use floats in quant finance optimization models) but try simulating a chaotic system and watch as floats are completely useless

It gets better when you have no idea how chaotic your system is!
My point was you can correct someone without being an rear end to them.

Nippashish
Nov 2, 2005

Let me see you dance!

pmchem posted:

Cool, mine too. You ignored the point about unit tests in my post. If you write scientific software that has numerical tests of floating point results, then as I'm sure you're aware, when you change (compiler / compiler flags / arch / libraries), the float results may slightly change. That's a pretty common occurrence, and is a reason why anyone involved with scientific software should be aware of floats. Not unusual at all.

Yes sorry I forgot to respond to the unit test part. The the version of this that I see most often is that the results of parallel reductions change because floats aren't associative so results can change even between multiple runs of the same binary on the same hardware. I deal with this in exactly the same way I deal with any other float comparison.

Anyway the point I'm making isn't that people should ignore that floats are not a perfect representation of real numbers. My point is that although the precise behavior of floats is quite complicated, there are very simple ways of thinking about them that explain their behavior at a level that is appropriate for the vast majority of people, including most of the people writing scientific software.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

QuarkJets posted:

Is writing bad analogies required for numerical analysis, now?

You're seriously fighting for the position that says "a person new to programming has to have a solid understanding of the difficult topic of numerical analysis before writing a program that uses floats". Is that really the hill that you want to die on?

well it keeps me in a job, so pragmatically no


but yes you should understand your tools before you use them, maybe read the fine manual as well

Cingulate posted:

I would think the entire neural network community largely ignores floating point issues, what with them running near-exclusively on single precision.


They have run the analysis and it doesn't matter to them. OP poster was running into self admitted errors and had no idea what was going on, because they had no idea what they were doing.



quote:


My point was you can correct someone without being an rear end to them.


it's not as fun

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Nippashish posted:


Anyway the point I'm making isn't that people should ignore that floats are not a perfect representation of real numbers. My point is that although the precise behavior of floats is quite complicated, there are very simple ways of thinking about them that explain their behavior at a level that is appropriate for the vast majority of people, including most of the people writing scientific software.

You're wrong and should feel wrong. If you're advocating writing scientific software or numerical software without understanding what's going on, please let me know what you make so I can never use it

Not everyone programs fart apps exclusively so its worth knowing when you can and when you can't ignore abstractions


OP go read http://floating-point-gui.de/basic/

joebuddah
Jan 30, 2005
Are there any descent python graphing packages that do not require pip or c++ packages?

I'm working with a manufacturing software packages that uses python 2.75. While it has some graphing options, I would like more robust options. In order for me to be able to use the package, the only thing I can do dump the library into the python libraries folder

QuarkJets
Sep 8, 2008

Malcolm XML posted:

well it keeps me in a job, so pragmatically no


but yes you should understand your tools before you use them, maybe read the fine manual as well

Malcolm XML posted:

You're wrong and should feel wrong. If you're advocating writing scientific software or numerical software without understanding what's going on, please let me know what you make so I can never use it

Not everyone programs fart apps exclusively so its worth knowing when you can and when you can't ignore abstractions


OP go read http://floating-point-gui.de/basic/

We're not talking about scientific software or numerical software. You keep saying that a careful analysis of numerical precision is necessary before writing any code at all if there's a chance that it will have a double variable somewhere in it. You're basically preaching premature optimization of anything more complex than a Hello World program

jusion
Jan 24, 2007


QuarkJets posted:

We're not talking about scientific software or numerical software. You keep saying that a careful analysis of numerical precision is necessary before writing any code at all if there's a chance that it will have a double variable somewhere in it. You're basically preaching premature optimization of anything more complex than a Hello World program
I think you have to be intellectually dishonest to think something like 0.1 + 0.2 == 0.3 would be rare in any sort of program. If you want to program you have to understand boolean logic. If you want to program you have to at least understand the basics of floating point math and its pitfalls. This isn't really an extreme position. Maybe Malcolm was a little mean, but come on...

SurgicalOntologist
Jun 17, 2004

Malcolm XML posted:

a complicated algorithm that compensates for the fact that the system is very sensitive to accumulated approximation error and a lot of whiskey when b/c even then long term behavior is sketchy
Do you have an actual algorithm in mind? Because if so I'd be curious to read up on it. I always figured that after solver issues (i.e. discretization error, stiffness, etc.) and measurement error on initial conditions, floating-point arithmetic is pretty low on the list of concerns.

But yeah, dealing with chaotic systems, good luck if you need to make specific predictions. Investigating the qualitative behavior of the system is more useful anyway.

In any case, you started by saying "floats are completely useless" for simulating complex systems, which I still don't understand--should I not be using floats? Or are just making the point that chaos magnifies errors? In which case, I have errors of much higher orders of magnitude I'm already concerned about.

QuarkJets
Sep 8, 2008

jusion posted:

I think you have to be intellectually dishonest to think something like 0.1 + 0.2 == 0.3 would be rare in any sort of program. If you want to program you have to understand boolean logic. If you want to program you have to at least understand the basics of floating point math and its pitfalls. This isn't really an extreme position. Maybe Malcolm was a little mean, but come on...

No no no, I'm arguing for an understanding of the basics. Malcolm is arguing for a far more extreme position than that

jusion
Jan 24, 2007


QuarkJets posted:

No no no, I'm arguing for an understanding of the basics. Malcolm is arguing for a far more extreme position than that
Ok - I think you may be talking past each other then, because his link (http://floating-point-gui.de/basic/) is not that.

QuarkJets
Sep 8, 2008

jusion posted:

Ok - I think you may be talking past each other then, because his link (http://floating-point-gui.de/basic/) is not that.

QuarkJets posted:

Is writing bad analogies required for numerical analysis, now?

You're seriously fighting for the position that says "a person new to programming has to have a solid understanding of the difficult topic of numerical analysis before writing a program that uses floats". Is that really the hill that you want to die on?

Malcolm XML posted:

well it keeps me in a job, so pragmatically no


but yes you should understand your tools before you use them, maybe read the fine manual as well

That page is "here are the basics", Malcolm's posts are saying that you actually need much more than a basic understanding. I think his intention was that a beginner should read all of the pages on that web site, not just the page that was linked.

pmchem
Jan 22, 2010


Cingulate posted:

I would think the entire neural network community largely ignores floating point issues, what with them running near-exclusively on single precision.

I dunno. I mean, a casual google search reveals several papers and posts on the topic; their fp issues are just different from most others'. They prefer to use as little precision as possible to get their useful result in order to do things like reduce file size issues for trained models: https://www.tensorflow.org/performance/quantization

shrike82
Jun 11, 2005

yup, google's TPUs use quantization to improve inference performance so you can't say that ML practitioners can ignore FP issues

LochNessMonster
Feb 3, 2005

I need about three fitty


baka kaba posted:

There's nothing wrong with what you were doing (and the results you were printing were still correct to a very high accuracy) - you just need to be aware that you might get some awkward numbers. Really what you needed to do was format your print output to a fixed number of decimal places, that's all, same as you would if you were doing some awkward division where you knew the answer would be like 7.4042780206425627001183

For other stuff, it really depends. If you're doing a test and you want to compare a result to an expected answer, and that answer is the result of a particular calculation (like a ratio), you can perform that calculation and compare to that instead of the literal result you expect. That way your expected answer will have the same error as the actual answer (because they represent the same floating point calculation) and they'll be equal

If your expected answer is a little harder to express, and you want to just say what the value you expect is, accept that the actual answer might not be exactly what you're looking for, but within a certain tolerance - like a real-world measurement. Usually in that case you'd specify an acceptable error amount and make sure the difference between the expected and actual answers doesn't exceed that

There's a python section on this stuff and it gives you some handy ways to deal with all these things

Just read some stuff on the Floating-Point Guide that was linked earlier as well as the official docs and it makes some more sense now. At leas now I know to round my floats when using them for basic calculations!

(and to use decimals if I want to do something with currency)

Cingulate
Oct 23, 2012

by Fluffdaddy

Malcolm XML posted:

it's not as fun
I generally don't do this, but- if your fun is being needlessly mean towards other people, here's some life advice for you: try doing that less. Try changing. You'll become a happier person, and contribute more to the lives of those around you.
I don't mean this to disparage you or as a counterargument to your position - which it is not - but as advice from someone who should've been given that lesson much earlier themselves, too.

shrike82 posted:

yup, google's TPUs use quantization to improve inference performance so you can't say that ML practitioners can ignore FP issues
They can, and do, largely ignore them. They can also try to reduce precision even more to get some performance benefits in certain applied cases.

(I'm obviously not saying these people are ignorant of the issues, just that the issues are largely irrelevant, and being ignored.)

Adbot
ADBOT LOVES YOU

shrike82
Jun 11, 2005

An ML practitioner or academic could decide to ignore precision based on their needs, but I'd find it hard to argue that one can make an informed decision without understanding the basics of floating point arithmetic.

No argument about Malcolm acting like a douchebag but hey, being a coder in the finance industry sucks so it's not surprising that people like him behave that way.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply