TIL (about the Dark Arts of HTML)
-
@pleegwat In GCC you can do
#define max(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; })
Then again an inline function would probably be more suitable.
-
@anonymous234 Macros always end ugly as fuck
-
@wharrgarbl said in TIL (about the Dark Arts of HTML):
Macros always end ugly as fuck
Why is why you should use a variadic template instead.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
@pleegwat In GCC you can do
#define max(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; })
Then again an inline function would probably be more suitable.
True, but that's not the typical implementation. And inline functions only support a single argument type.
@asdf said in TIL (about the Dark Arts of HTML):
@wharrgarbl said in TIL (about the Dark Arts of HTML):
Macros always end ugly as fuck
Why is why you should use a variadic template instead.
I don't know much C++ but somehow I doubt that's any better.
-
@pleegwat said in TIL (about the Dark Arts of HTML):
True, but that's not the typical implementation. And inline functions only support a single argument type.
You can use
__builtin_types_compatible_p(__typeof__(a), int)
(etc.) in a macro to do selection between the inline function implementations. Because you know you want to mix both macros and inline functions!
-
@dkf said in TIL (about the Dark Arts of HTML):
@pleegwat said in TIL (about the Dark Arts of HTML):
True, but that's not the typical implementation. And inline functions only support a single argument type.
You can use
__builtin_types_compatible_p(__typeof__(a), int)
(etc.) in a macro to do selection between the inline function implementations. Because you know you want to mix both macros and inline functions!Can you add some template
fuckerywizardry in there too? I need my fix!
-
I love how this discussion is proving my first comment right...
-
@dreikin Not in the code I took that stuff from; it's pure C. I'm sure I could if I was using C++ though.
-
@dkf said in TIL (about the Dark Arts of HTML):
@dreikin Not in the code I took that stuff from; it's pure C. I'm sure I could if I was using C++ though.
>.< Whoops, forgot that part. Maybe some pointer abuse? Nah, that would just seem gratuitous.
-
@zecc said in TIL (about the Dark Arts of HTML):
@anonymous234 said in TIL (about the Dark Arts of HTML):
TIL the C library does not have min() or max() functions.
I guess because making things easier would defeat the purpose of C.
It would have to be a family of functions to avoid unnecessary conversions in hot code: mini/maxi, minf/maxf, minui/maxui, etc.
OK, I partially lied. C actually does have
double fmin(double, double); float fminf(float, float); long double fminl(long double, long double);
in <math.h>.
But none for integers. Which is even dumber IMO. Like couldn't they just sneak an
imin(int, int)
in there?Also GCC has its own extension for C++ code, implemented as an operator:
a <? b
means min(a, b).
-
@anonymous234 I wouldn't be surprised if the floating point spec allows for cases where
a < b ? a : b
does not work.
-
@dreikin said in TIL (about the Dark Arts of HTML):
Maybe some pointer abuse?
Not this time. There's always another day though!
-
@pleegwat said in TIL (about the Dark Arts of HTML):
I wouldn't be surprised if the floating point spec allows for cases where
a < b ? a : b
does not work.Maybe something with negative zero or NaN? The rest of the IEEE float spec is surprisingly non-crazy.
-
@pleegwat
Yes, there is a case where the result would be potentially undesirable: Think of the case wherea
isNaN
andb
is a regular float.fmin*
does the right thing in that case:1-3) Returns the smaller of two floating point arguments, treating NaNs as missing data (between a NaN and a numeric value, the numeric value is chosen).
Edit: 'd because I added the quote. Goddammit!
-
@asdf said in TIL (about the Dark Arts of HTML):
1-3) Returns the smaller of two floating point arguments, treating NaNs as missing data (between a NaN and a numeric value, the numeric value is chosen).
I'd really have expected it to return NaN.
After all, 1+NaN = NaN, etc.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
@asdf said in TIL (about the Dark Arts of HTML):
1-3) Returns the smaller of two floating point arguments, treating NaNs as missing data (between a NaN and a numeric value, the numeric value is chosen).
I'd really have expected it to return NaN.
After all, 1+NaN = NaN, etc.
And that indicates you might as well do it yourself -
(isnan(a) || a < b) ? a : b
vs.(isnan(b) || a < b) ? a : b
.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
I'd really have expected it to return NaN.
Why? The minimum is defined as the smallest number, and NaN is not smaller or greater than anything.
-
@asdf said in TIL (about the Dark Arts of HTML):
@anonymous234 said in TIL (about the Dark Arts of HTML):
I'd really have expected it to return NaN.
Why? The minimum is defined as the smallest number, and NaN is not smaller or greater than anything.
Typically, any floating-point operation involving NaN yields NaN.
Apart from
isNaN()
, which yields a Boolean.
-
@asdf said in TIL (about the Dark Arts of HTML):
and NaN is not smaller or greater than anything.
Precisely, which is why the only valid result of min(1, NaN) is "not applicable". Which is almost what NaN means.
Maybe they'd have to define NaB (Not a boolean)?
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
Maybe they'd have to define
NaBFILE_NOT_FOUND?YMBNH
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
Maybe they'd have to define NaB (Not a boolean)?
isn't that called NULL?
-
-
Don't know if the source is reliable, but:
-
TIL the EPA regulation for a nuclear waste repository in Yucca mountain extend for the next 10,000 years. After a lawsuit, that period was extended to one million years.
-
@zecc said in TIL (about the Dark Arts of HTML):
Don't know if the source is reliable
/r/todayilearned is extremely reliable, because
- They give out "awards" for debunking misleading headlines
- It's reddit, so it's naturally rich in pedantic dickweeds eager to prove others wrong
-
@anonymous234 So we're just missing the
awards?
-
@dkf said in TIL (about the Dark Arts of HTML):
@anonymous234 So we're just missing the
awards?Everyone except one unnamed forum member, yes.
-
@asdf said in TIL (about the Dark Arts of HTML):
@dkf said in TIL (about the Dark Arts of HTML):
@anonymous234 So we're just missing the
awards?Everyone except one unnamed forum member, yes.
i hates s they taste all gamey and gross. and they're mean bastards too. bunnies and chickens are much better tasting and not nearly so mean too.
well except for that one rooster, but i'll get him one day.........
-
@accalia said in TIL (about the Dark Arts of HTML):
well except for that one rooster, but i'll get him one day.........
Must... resist... obvious... joke...
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
@accalia said in TIL (about the Dark Arts of HTML):
well except for that one rooster, but i'll get him one day.........
Must... resist... obvious... joke...
Why Resist?
-
@accalia said in TIL (about the Dark Arts of HTML):
@asdf said in TIL (about the Dark Arts of HTML):
@dkf said in TIL (about the Dark Arts of HTML):
@anonymous234 So we're just missing the
awards?Everyone except one unnamed forum member, yes.
i hates s they taste all gamey and gross. and they're mean bastards too. bunnies and chickens are much better tasting and not nearly so mean too.
well except for that one rooster, but i'll get him one day.........
And here I thought it was @Perverted_Vixen who was always trying to get the cock.
-
@anonymous234
Is /r/todayilearned the New and BetterTM replacement for Snopes?
-
TIL that the Native American tribes had slaves, and that slavery was even built into the Cherokee's constitution. (Many of them liked the idea of copying a lot of the "white man's" ways.)
Native American slave ownership
Actually, I don't remember if I knew it before; I'm not really all that surprised about it.
-
TIL @accalia's life goal is to eat cock.
-
@izzion said in TIL (about the Dark Arts of HTML):
TIL @accalia's life goal is to eat cock.
I was going to mention that I had one of those, but then I remembered that she likes to use teeth.
-
TIL font-based emoji have bold and italic forms:
🛒 🛒 🛒 🛒
At least, I'm seeing that on Windows 10.
-
@raceprouk GG Windows 7/Chrome:
-
For those who can't see it:
-
Windows ⏋
-
Win 7 Chrome
-
I'm obviously missing some super important fonts then
-
@raceprouk Win 7 FF:
edit: same computer, but Chrome:
-
@jaloopa said in TIL (about the Dark Arts of HTML):
I'm obviously missing some super important fonts then
No, you're just using (see above post).
-
@raceprouk said in TIL (about the Dark Arts of HTML):
TIL font-based emoji have bold and italic forms:
🛒 🛒 🛒 🛒
At least, I'm seeing that on Windows 10.
Seems legit.
-
TIL Word will bug you to write things more concisely.
Look, Word, you don't need to teach me concision. If it were up to me, all documents would be 5 times shorter than they are. But apparently writing long documents is necessary to prove that you're smart, so I have to do it too.
-
@anonymous234 It doesn't help that half its suggestions change the meaning of the sentence into nonsense.
-
@raceprouk said in TIL (about the Dark Arts of HTML):
@anonymous234 It doesn't help that half its suggestions change the meaning of the sentence into nonsense.
Grammar is hard, let's travel to shopping
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
TIL Word will bug you to write things more concisely.
Look, Word, you don't need to teach me concision. If it were up to me, all documents would be 5 times shorter than they are. But apparently writing long documents is necessary to prove that you're smart, so I have to do it too.
In high school algebra my teacher once held up two different papers for the class to see (mine, written small as is my style, and another written with large rounded letters) to illustrate that effect, in terms of who looked like they'd done more work.
-
@jaloopa said in TIL (about the Dark Arts of HTML):
Grammar is hard, let's travel to shopping
This reminds of the Chenglish status reports in my team's standup meetings.
-
TIL that, in PHP, while you can have an array of anonymous functions, you can't have that array be a class property.
Sticking it in a method and just returning the array is fine though. If there's valid reasoning behind this... I don't want to know it, honestly.