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
The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Xarn posted:

no you don't. nobody does. :suicide:


(For real though, to actually understand precision issues, you have to be domain expert in floating point computation and in whatever you computation is doing, because all of exact comparison, absolute margin comparison, relative margin comparison, ULP comparison, can be the right or wrong choice, dependent on what you are actually doing)

To be clear: I know just enough to know they exist lol. I'd ask somebody smarter if I got into a situation where I had to use them.

Adbot
ADBOT LOVES YOU

Dylan16807
May 12, 2010

Xarn posted:

no you don't. nobody does. :suicide:


(For real though, to actually understand precision issues, you have to be domain expert in floating point computation and in whatever you computation is doing, because all of exact comparison, absolute margin comparison, relative margin comparison, ULP comparison, can be the right or wrong choice, dependent on what you are actually doing)
The one I find really interesting is fsin(pi). Depending on how you view the problem, the answer you get on Intel chips is either perfectly fine or utter garbage that only has four digits of precision.
https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/

1337JiveTurkey
Feb 17, 2005

https://web.archive.org/web/20110812023545/http://blogs.oracle.com/jag/entry/transcendental_meditation

Related to that, part of why Java's trig functions are so slow is they exactly map their input into the range [-pi/4, pi/4] before using the hardware function to do the rest.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
if only we used degrees we wouldn't have this problem

TheresaJayne
Jul 1, 2011
Why not try the usual horror.
open Calculator (not in windows 10 though - they finally fixed it)

4 Sqrt -2 = 0.0000000000000001 -29 (or something similar)

Dross
Sep 26, 2006

Every night he puts his hot dogs in the trees so the pigeons can't get them.

TheresaJayne posted:

Why not try the usual horror.
open Calculator (not in windows 10 though - they finally fixed it)

4 Sqrt -2 = 0.0000000000000001 -29 (or something similar)

A non techie friend posted a screenshot on Facebook the other day of him being forced to restart the calculator app due to an update. He captioned it “did they change math??” and I thought to myself “in a sense...yeah”

Goreld
May 8, 2002

"Identity Crisis" MurdererWild Guess Bizarro #1Bizarro"Me am first one I suspect!"

Xarn posted:

no you don't. nobody does. :suicide:


(For real though, to actually understand precision issues, you have to be domain expert in floating point computation and in whatever you computation is doing, because all of exact comparison, absolute margin comparison, relative margin comparison, ULP comparison, can be the right or wrong choice, dependent on what you are actually doing)

I spent an entire summer making some polygonal CSG code robust ie. guaranteeing epsilons for parity checks were within correct thresholds for floating point operations, amongst other things (you have to pay attention to every multiply, add and divide and find some creative algebra to minimize epsilon and pigeonhole the math). Imagine doing 1000 consecutive Boolean intersections on a mesh and trying to keep the result to not be nightmarish.

I can confidently say I don’t know a drat thing about floating point numbers, they have terrifyingly unintuitive edge cases. Even ignoring stupid processor issues like using == checks to detect NAN’s.

Goreld fucked around with this message at 19:55 on Jun 16, 2019

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


What Every Computer Scientist Should Know About Floating-Point Arithmetic

Coming in at a mere 45 pages, this should be top of your summer reading list.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

ultrafilter posted:

What Every Computer Scientist Should Know About Floating-Point Arithmetic

Coming in at a mere 45 pages, this should be top of your summer reading list.

Jesus the text is really small too

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Medium.

fritz
Jul 26, 2003

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

"fritz's post history".

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
PornHub video titles

FlapYoJacks
Feb 12, 2009

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Elon Musk Tweet.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Click-bait, assuming you have an iq above about 30

Absurd Alhazred
Mar 27, 2010

by Athanatos

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Click-ward.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Doc Hawkins posted:

What's the word for the opposite of click-bait? Like, a title that makes you incredibly averse to the idea of reading something.

Clickcrow

fritz
Jul 26, 2003

Soricidus posted:

Click-bait, assuming you have an iq above about 30

Are you one of those "advertising doesn't work on me" people?

fritz
Jul 26, 2003

:yeshaha:
https://twitter.com/jfbastien/status/1139298419988549632

Ruggan
Feb 20, 2007
WHAT THAT SMELL LIKE?!


The caret is XOR - that’s the issue, right? A fundamental misunderstanding of C operators?

ToxicFrog
Apr 26, 2008


Ruggan posted:

The caret is XOR - that’s the issue, right? A fundamental misunderstanding of C operators?

That's a problem, yes; 2^32 in C is 34, not 2³².

There's also the problem that even if it were 2³², if (signed) int is 32 bits, you can't represent (2³²-1) in it, so that comparison is always true and you have an infinite loop. So even if ^ worked the way the author thinks it does, that code is wrong.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I've been really impressed with how big I can make Javascript arrays recently. I had to write a script that would do something to all the records in a table and I basically just went ahead and fetched them all. There were some few hundred thousand records Javascript totally dealt with it.

1337JiveTurkey
Feb 17, 2005

The tricky thing about Javascript arrays is that they're implemented separately from key-value stores on objects which can make them far faster, but if you do anything that forces the implementation to deoptimize them, they get really slow.

Soricidus
Oct 21, 2010
freedom-hating statist shill

fritz posted:

Are you one of those "advertising doesn't work on me" people?

Clickbait headlines are to advertising as 419 scam emails are to social engineering. One works on everybody, the other is specifically and deliberately targeting people with poor judgment.

xtal
Jan 9, 2011

by Fluffdaddy

Soricidus posted:

Clickbait headlines are to advertising as 419 scam emails are to social engineering. One works on everybody, the other is specifically and deliberately targeting people with poor judgment.

Clickbait works on anybody, look at this blog post about it

FlapYoJacks
Feb 12, 2009
I did a small interview for Amazon and apparently failed the coding test?

Apparently, it wasn't O notation enough?

*edit*

The exercise was:
Make a function that, given a string with brackets in it returns true if the string has the same order of closing brackets.
IE:
"{$$[fdasfsa<fdaf>####]%@#}" == True
"{$$[ff}fff]" == False

My solution was to parse the string and dump the opening and closing brackets into separate arrays, and then
loop through said arrays to make sure that the opening bracket array matched the closing bracket array.

I'm sure there's a way more clever solution with recursion or some poo poo they wanted, but w/e. :shrug:

FlapYoJacks fucked around with this message at 20:27 on Jun 17, 2019

JehovahsWetness
Dec 9, 2005

bang that shit retarded
Use a stack and only iterate the string once?

CPColin
Sep 9, 2003

Big ol' smile.
That might be asking if the brackets are nested properly. You could push the type of bracket onto a stack when you see an opening brackets and pop off the stack when you see a closing one. Return false early if the popped value doesn't match the current closing bracket and return true if the stack is empty at the end.

Nth Doctor
Sep 7, 2010

Darkrai used Dream Eater!
It's super effective!


CPColin posted:

That might be asking if the brackets are nested properly. You couls push the type of bracket onto a stack when you see an opening brackets and pop off the stack when you see a closing one. Return false early if the popped value doesn't match the current closing bracket and return true if the stack is empty at the end.

Was gonna post exactly this so I'll quote instead.

QuarkJets
Sep 8, 2008

ratbert90 posted:

I did a small interview for Amazon and apparently failed the coding test?

Apparently, it wasn't O notation enough?

*edit*

The exercise was:
Make a function that, given a string with brackets in it returns true if the string has the same order of closing brackets.
IE:
"{$$[fdasfsa<fdaf>####]%@#}" == True
"{$$[ff}fff]" == False

My solution was to parse the string and dump the opening and closing brackets into separate arrays, and then
loop through said arrays to make sure that the opening bracket array matched the closing bracket array.

I'm sure there's a way more clever solution with recursion or some poo poo they wanted, but w/e. :shrug:

A stack of open brackets and a break statement the loop exits the first time that popping does not match a character in the string

QuarkJets fucked around with this message at 20:51 on Jun 17, 2019

FlapYoJacks
Feb 12, 2009
Fair enough. This is the coding horrors thread, and I routinely am a bad programmer. :smith:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The more important thing than the performance is that your solution doesn't have a problem with a)b(c when it presumably should. That should be obvious to you from the fact that your solution clearly erases inter-ordering differences between open and close brackets.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Strip everything except brackets from the string, if it's an odd length fail, then match half the indexes against the opposite using a switch statement.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Something like
JavaScript code:
function check(str) {
    const chars = str.split('').filter(char => '{}[]()'.includes(char));
    if (chars.length % 2 !== 0) return false;
    while (chars.length > 0) {
        const [start, end] = [chars.shift(), chars.pop()];
        if (start === '[' && end === ']') continue;
        if (start === '{' && end === '}') continue;
        if (start === '(' && end === ')') continue;
        return false;
    }
    return true;
}

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Nolgthorn posted:

Strip everything except brackets from the string, if it's an odd length fail, then match half the indexes against the opposite using a switch statement.

Ah your second post makes it clear for me. Only caring about the first and last index solves the problem nicely.

I have to wonder, is removing elements from both the beginning and end of an array more expensive than just a single passthrough with a bunch of push()es onto a separate buffer though?

Happy Thread fucked around with this message at 02:31 on Jun 18, 2019

QuarkJets
Sep 8, 2008

Dumb Lowtax posted:

Ah your second post makes it clear for me. Only caring about the first and last index solves the problem nicely.

I have to wonder, is removing elements from both the beginning and end of an array more expensive than just a single passthrough with a bunch of push()es onto a separate buffer though?

I want to say almost definitely, yes, but the difference is probably negligible for a single use

I think the key is probably working your way towards an answer that is correct first, and then working on optimizing it. They're using code review to suss out how you solve problems, so if you just provide an answer that gives wrong results and offer no further refinement then that's bad.

Mad Jaqk
Jun 2, 2013

Dumb Lowtax posted:

Ah your second post makes it clear for me. Only caring about the first and last index solves the problem nicely.

I have to wonder, is removing elements from both the beginning and end of an array more expensive than just a single passthrough with a bunch of push()es onto a separate buffer though?

It depends on how the language implements the data structure in question, but you should assume that yes, it's more expensive. The easy way to think about it is that removing an item from the front of an array requires shifting every other element in the array forward one position, so that's O(n) time, whereas pushing or popping from the end of the array doesn't require modifying any of the other elements, so it's O(1).

Again, in some cases the underlying data structure works differently and that's not the case; the example I'm familiar with is Python's collections.deque, which allows efficient operations on both ends (at the cost of being more expensive to interact with data in the middle). I want to say that Lisp also uses some form of doubly-linked list as its default sequence type, but I've never worked with the language and could be remembering wrong.

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED

Mad Jaqk posted:

It depends on how the language implements the data structure in question, but you should assume that yes, it's more expensive. The easy way to think about it is that removing an item from the front of an array requires shifting every other element in the array forward one position, so that's O(n) time, whereas pushing or popping from the end of the array doesn't require modifying any of the other elements, so it's O(1).

Again, in some cases the underlying data structure works differently and that's not the case; the example I'm familiar with is Python's collections.deque, which allows efficient operations on both ends (at the cost of being more expensive to interact with data in the middle). I want to say that Lisp also uses some form of doubly-linked list as its default sequence type, but I've never worked with the language and could be remembering wrong.

This, except the opposite. In the worst case it's O(n) for both operations, but in some cases you can just advance a pointer one element and avoid allocating extra memory.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

QuarkJets posted:

I think the key is probably working your way towards an answer that is correct first, and then working on optimizing it. They're using code review to suss out how you solve problems, so if you just provide an answer that gives wrong results and offer no further refinement then that's bad.

Yeah, if I had to guess, the interviewers are asking this question for three reasons:

  • It's complex enough that the candidate will need to communicate with you in order to understand what's being asked, which gives you a chance to evaluate their technical communication skills.
  • There are enough traps in the solution space that you can get a good idea of how the candidate is thinking and whether they're being adversarial towards their proposed solutions or just slinging ideas out there and hoping they satisfy requirements.
  • If the candidate gets to a working solution quickly, there's plenty of room to talk about performance.

Dumb Lowtax posted:

I have to wonder, is removing elements from both the beginning and end of an array more expensive than just a single passthrough with a bunch of push()es onto a separate buffer though?

Yes, because (1) the maximum nesting depth is at most half the length of the string and can reasonably be expected to be far less and (2) stacks are a significantly more efficient data structure than strings (unless your language can't do generic data structures without boxing the elements).


(a)b{c}

Adbot
ADBOT LOVES YOU

Unspun
Apr 6, 2007

You might feel your bones loose or discomforting.
It's normal!
Your legs are just developing and changing into being a Milky Point Millionaire.
Use a pointer at each end of the string and move them towards each other. Stacks? Arrays?! Christ! gently caress!!

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