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
Soricidus
Oct 21, 2010
freedom-hating statist shill

Volguus posted:

Hahaha. This reminds me of another JSP page that I had the pleasure of seeing a few years back: It was holding the currently logged in users in a static java.util.Hashtable. 2 people could not log in/browse at the exact same time or the application would crash.
Why did it crash? Hashtable is supposedly thread-safe so it can’t be that.

Adbot
ADBOT LOVES YOU

Volguus
Mar 3, 2009

Soricidus posted:

Why did it crash? Hashtable is supposedly thread-safe so it can’t be that.

Hashtable is not thread safe. Methods in it are synchronized, that's true, so you can call "put" from 2 different threads and it works fine. But you can't iterate over it while trying to call put, for example. In general, in java, if you need a thread safe map one should use ConcurrentHashMap.

Nth Doctor
Sep 7, 2010

Darkrai used Dream Eater!
It's super effective!


Volguus posted:

Hahaha. This reminds me of another JSP page that I had the pleasure of seeing a few years back: It was holding the currently logged in users in a static java.util.Hashtable. 2 people could not log in/browse at the exact same time or the application would crash. That was in addition to its many other issues.

"Can you fix it?" was the question.
"No" was the only possible answer that i could give.

We had something similarly horrific in our DBManager class through which all db connectivity in the platform flowed. As a manager it was a Singleton, but one of the class level static fields of the thing was WHO IS CONNECTING. Normally this wasn't a problem because we would at least set the thing at the last possible moment before connections opened, until we happened to have two requests come in at the exact same millisecond. Ugh that was a bad night.

Thankfully my only involvement in it was in the aftermath because I was one of the few devs who knew how to read packet traces.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Volguus posted:

Hashtable is not thread safe. Methods in it are synchronized, that's true, so you can call "put" from 2 different threads and it works fine. But you can't iterate over it while trying to call put, for example. In general, in java, if you need a thread safe map one should use ConcurrentHashMap.

Hashtable has the worst kind of thread-safety, in that you pay the performance cost of locking but don't actually get any beneficial semantics in exchange.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I think you can read and write elements atomically; the problem is that that’s not really an adequate API for a concurrent dictionary. But iterating isn’t a good example of why, both because IIRC you can safely iterate it (by synchronizing on it yourself) and because iteration is not an operation you should generally be using on concurrent data structures.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Java code:
@DontIterateMeBro
public class HashTable

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
code:
public class HttpClientFactory : HttpClient
{
	public HttpClientFactory(string uri)
	{
		BaseAddress = new Uri(uri);
	}
}
As seen in such classic usage cases such as
code:
var httpClient = new HttpClientFactory("http://some.address")
{
	Timeout = TimeSpan.FromMinutes(10)
};
:raise:

No Safe Word
Feb 26, 2005

Cuntpunch posted:

code:
public class HttpClientFactory : HttpClient
{
	public HttpClientFactory(string uri)
	{
		BaseAddress = new Uri(uri);
	}
}
As seen in such classic usage cases such as
code:
var httpClient = new HttpClientFactory("http://some.address")
{
	Timeout = TimeSpan.FromMinutes(10)
};
:raise:
smh if you don't build a new factory to produce every single widget

Kuule hain nussivan
Nov 27, 2008

Just found out that our software provider who have trouble providing fixes for relatively simple bugs, have decided to not use on open source map solution with the new GIS module, but will instead roll out their own implementation. Fun times ahead.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Do they have access to ships, cartographers, or constellation-tracking equipment? Or are they gonna drive around in their car taking GPS readings

Kuule hain nussivan
Nov 27, 2008

Dumb Lowtax posted:

Do they have access to ships, cartographers, or constellation-tracking equipment? Or are they gonna drive around in their car taking GPS readings
They did complain about not having enough time to answer the issues we report, so they must be busy with something else.

Volguus
Mar 3, 2009
code:
if (s1 BETTER_THAN WORST_SCORE)
with

code:
/**
 * Is one score better than another?
 */
#define BETTER_THAN >

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Do they also define IS_THE_SAME because if so I'm behind them.

Volguus
Mar 3, 2009

Nolgthorn posted:

Do they also define IS_THE_SAME because if so I'm behind them.

No, only

code:
#define WORSE_THAN <
because of course.

CPColin
Sep 9, 2003

Big ol' smile.
At least it's not:
code:
#define BETTER_THAN >=
#define WORSE_THAN <=

redleader
Aug 18, 2005

Engage according to operational parameters
Y'all are unnecessarily afraid of some literate programming.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm being triggered by these worth assignments, who's to say one number is better than another??

Dylan16807
May 12, 2010

CPColin posted:

At least it's not:
code:
#define BETTER_THAN >
#define WORSE_THAN <=

[...200 lines...]

#define BETTER_THEN >=
#define WORSE_THEN <=

Doom Mathematic
Sep 2, 2008

Scaramouche posted:

I'm being triggered by these worth assignments, who's to say one number is better than another??

You're having a panic attack because of bad code?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Doom Mathematic posted:

You're having a panic attack because of bad code?

More of a Guru Meditation

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

If you did
code:
#define BETTER_THEN(x,y) if (x>=y) {
Then imagine the pseudocode you could write

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Subtly grammatically incorrect literate programming, now there’s a trend I could jump on!

iospace
Jan 19, 2038


The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible?

MrMoo
Sep 14, 2000

I've seen code like that in production, namely the lack of a free alongside stupid things like calling strdup doing one test and abandoning the memory.

iospace
Jan 19, 2038


jit bull transpile posted:

So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible?


You tell me (yes that's python and not a C-like, sue me)

iospace
Jan 19, 2038


MrMoo posted:

I've seen code like that in production, namely the lack of a free alongside stupid things like calling strdup doing one test and abandoning the memory.

Could be Java :v:

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.

jit bull transpile posted:

So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible?

I don't think so, but it is different from return (x < 0.0) in exactly one situation

-0.0 is a valid floating point value, and -0.0 < 0.0 evaluates to false

iospace
Jan 19, 2038


Jeb Bush 2012 posted:

I don't think so, but it is different from return (x < 0.0) in exactly one situation

-0.0 is a valid floating point value, and -0.0 < 0.0 evaluates to false

-0 is still 0. So therefore, it's false because it's less than, not less than or equal to

:goonsay:

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.

iospace posted:

-0 is still 0. So therefore, it's false because it's less than, not less than or equal to

:goonsay:

oh sure, I'm not saying it's the wrong answer (and if the output of your code depends on whether -0.0 < 0.0, something has almost certainly gone very wrong), just that it's the only situation I can think of where the weird stringcasting code would give a different answer from returning x < 0.0

JawnV6
Jul 4, 2004

So hot ...

jit bull transpile posted:

So I assume there's potential for very slightly negative floats to compare as not less than 0 and they solved this issue in the most ridiculous way possible?
No. There's a sign bit. That doesn't change for the subnormal numbers, they just needed to check it.

Floating point does a lot with the space it has. The biggest trick is a hidden '1', every binary floating point number would look like 1.010101 x 210101, so the leading "1." is dropped. To represent those very small numbers the exponent of '0' indicates that there's no leading "1.".

I thought it might have something to do with not caring if the input was a 32bit float or 64bit? A 20-character string is properly sized for a 64bit float, which can expand to 17 significant decimal digits plus 3 for the the sign, decimal point, and terminating \0. But I think it's just a waste of 8 bytes, per call.

The most obvious optimization is using 'snprintf' with the size set to 1 to (hopefully) bail once the stringifier has sussed out that sign bit.

Absurd Alhazred
Mar 27, 2010

by Athanatos

Kuule hain nussivan posted:

Just found out that our software provider who have trouble providing fixes for relatively simple bugs, have decided to not use on open source map solution with the new GIS module, but will instead roll out their own implementation. Fun times ahead.

Ahaha. AHAHAHAHA. AHAHAHAHAHAHAHAHAHA

Sure. Yes. Professional software outfits at the very least use established open-source libraries like GDAL if they're cheap, but sure, I bet this one podunk outfit is going to outdo all of them. :allears:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

JawnV6 posted:

No. There's a sign bit. That doesn't change for the subnormal numbers, they just needed to check it.

Floating point does a lot with the space it has. The biggest trick is a hidden '1', every binary floating point number would look like 1.010101 x 210101, so the leading "1." is dropped. To represent those very small numbers the exponent of '0' indicates that there's no leading "1.".

I thought it might have something to do with not caring if the input was a 32bit float or 64bit? A 20-character string is properly sized for a 64bit float, which can expand to 17 significant decimal digits plus 3 for the the sign, decimal point, and terminating \0. But I think it's just a waste of 8 bytes, per call.

The most obvious optimization is using 'snprintf' with the size set to 1 to (hopefully) bail once the stringifier has sussed out that sign bit.

Cool. I know just enough about float to understand precision issues but wasn't sure if that extended to comparisons between zero and a really small negative number.

Xarn
Jun 26, 2015
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)

MononcQc
May 29, 2007

Volguus posted:

code:
if (s1 BETTER_THAN WORST_SCORE)
with

code:
/**
 * Is one score better than another?
 */
#define BETTER_THAN >

How else are you going to make the code work both for basketball and golf?

Beef
Jul 26, 2004
And how else am I going to make absolutely sure the compiler will inline it?

VikingofRock
Aug 24, 2008




MononcQc posted:

How else are you going to make the code work both for basketball and golf?

Easy.

code:

#define GOLF 1
#define BASKETBALL 2

Now the code correctly shows that BASKETBALL BETTER_THAN GOLF.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



VikingofRock posted:

Easy.

code:
#define GOLF 1
#define BASKETBALL 2
Now the code correctly shows that BASKETBALL BETTER_THAN GOLF.

You can just go ahead and #define GOLF LONG_MIN

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Jeb Bush 2012 posted:

I don't think so, but it is different from return (x < 0.0) in exactly one situation

-0.0 is a valid floating point value, and -0.0 < 0.0 evaluates to false

Your standard library may write a NaN value with its sign bit set as "-nan", but since it's a NaN that comparison is still false. So the function differs from a plain compare in at least two situations :eng101:

Adbot
ADBOT LOVES YOU

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.

Bonfire Lit posted:

Your standard library may write a NaN value with its sign bit set as "-nan", but since it's a NaN that comparison is still false. So the function differs from a plain compare in at least two situations :eng101:

maybe. python prints NaN with a set sign bit as just "nan", but I haven't tried writing it in C (and it could be implementation-dependent anyway I guess)

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