|
if( Math.Abs( x - y ) < 0 ) { ... } In bizaro world where math.abs can return a non-absolute value.
|
# ? Jan 28, 2011 16:50 |
|
|
# ? Apr 27, 2024 14:23 |
|
Perhaps Math.abs() is modified at runtime to control the behavior of that code.
|
# ? Jan 28, 2011 16:59 |
|
You never know what future versions will do. Better safe than sorry.
|
# ? Jan 28, 2011 18:31 |
|
YeOldeButchere posted:You never know what future versions will do. Better safe than sorry. I realize you're joking but surely an assertion would make more sense if that was the goal. I've definitely seen assertions for e.g. C++ STL containers, like this: code:
|
# ? Jan 28, 2011 23:15 |
|
NotShadowStar posted:Wow, people keep touting that Apple doesn't have problems with OSX because nobody has targeted it. I don't think that's the case, because Apple just uses standard unix permissions instead of weirdo crap like this. Finder doesn't run in a special privilege, it asks permission just like every singe other application. Windows doesn't have many users who care about security, their priority tends towards performance and/or usability. Only company security officers really cares. CEOs tend to only after the company got owned. They don't blame the OS afterward though, since operating systems are hard to change (I guess?); they just place security devices around the OS. Microsoft is happy. Customers are happy. Attackers are happy. Yay! At the end of the day, they're both oriented to serve their marginally technical customer base. That base doesn't want UAC prompts; they don't understand the threat posed anyhow. Unfortunately, that provides a pretty soft target for criminals, although OS hardening has significantly strengthened Windows (now it is only somewhat easy to pwn, vs trivial). edit: clarified which SO/CEOs Kelson fucked around with this message at 19:23 on Jan 29, 2011 |
# ? Jan 29, 2011 19:10 |
|
Dnatural posted:In bizaro world where math.abs can return a non-absolute value. quote:Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative. So, not that crazy, in some languages.
|
# ? Jan 30, 2011 00:42 |
|
No, I'm fairly certain that Java is a crazy language.
|
# ? Jan 30, 2011 02:00 |
|
Kind of disconcerting that the absolute value function could return a negative value. What do other languages do? (I mean languages in which the minimum representable integer is greater in absolute value than the maximum representable integer, obviously.)
|
# ? Jan 30, 2011 02:33 |
|
Hammerite posted:(I mean languages in which the minimum representable integer is greater in absolute value than the maximum representable integer, obviously.) AFAIK this should ALWAYS be the case (and is a function of hardware, not language)
|
# ? Jan 30, 2011 02:43 |
|
Hammerite posted:Kind of disconcerting that the absolute value function could return a negative value. What do other languages do? (I mean languages in which the minimum representable integer is greater in absolute value than the maximum representable integer, obviously.) ghci> abs (minBound :: Int) -9223372036854775808 < Vanadium> cout << std::abs(std::numeric_limits<int>::min()) < cout> -2147483648
|
# ? Jan 30, 2011 02:45 |
|
TasteMyHouse posted:AFAIK this should ALWAYS be the case (and is a function of hardware, not language) Isn't the entire purpose of not coding in assembly defeated this way? I can definitely see fun things happening because someone assumed that abs would always be positive, given that the actual abs function is always positive. You know, in this reality. By definition.
|
# ? Jan 30, 2011 02:50 |
|
The Reaganomicon posted:Isn't the entire purpose of not coding in assembly defeated this way? I can definitely see fun things happening because someone assumed that abs would always be positive, given that the actual abs function is always positive. You know, in this reality. By definition. Its just kind of a difficult problem to solve. In two's complement, the most negative number HAS no positive representation. How would you propose to handle this? In C, the behavior is undefined... I personally would prefer having it be defined, so that if it actually is a problem in my code I can anticipate the exact case and handle it.
|
# ? Jan 30, 2011 02:59 |
|
TasteMyHouse posted:Its just kind of a difficult problem to solve. In two's complement, the most negative number HAS no positive representation. How would you propose to handle this? In C, the behavior is undefined... I personally would prefer having it be defined, so that if it actually is a problem in my code I can anticipate the exact case and handle it. I understand the reasoning, but having a single edge case act in a way contrary to what you would normally expect seems to be a Bad Solution. They probably considered this when writing abs, but christ that's ugly.
|
# ? Jan 30, 2011 03:09 |
|
If you're calling abs(INT_MIN), something has probably gone wrong already.
|
# ? Jan 30, 2011 03:14 |
|
The Reaganomicon posted:I understand the reasoning, but having a single edge case act in a way contrary to what you would normally expect seems to be a Bad Solution. They probably considered this when writing abs, but christ that's ugly. I just don't know what you want to happen. 2's complement is built into the hardware, and it is a natural consequence of 2's complement that there is a value that sticks out in this way. It is not possible for abs to return a value consistent with its normal behavior on this input. and no one is going to throw out the advantages of 2'complement so that abs makes more sense
|
# ? Jan 30, 2011 03:35 |
|
The only logical outcome for abs(INT_MIN) would be for some form of exception. I like INT_MIN, it's an edge case that is often forgotten. I've got calculator programs to segfault with it.
|
# ? Jan 30, 2011 03:54 |
|
One solution might've been to shift INT_MIN up by one, making the range for negative numbers equal to the range for positive numbers. That has problems too- discarding that pesky value means you can't use a signed int to store an arbitrary 32-bit hex value for masking.
|
# ? Jan 30, 2011 03:56 |
|
I would have preferred the function throw an exception rather than return a negative number.
|
# ? Jan 30, 2011 06:10 |
|
code:
|
# ? Jan 30, 2011 06:22 |
|
Man I'm nowhere near it right at this moment but Drupal puts a metric fuckton of poo poo in HTML headers by default. I had never even heard of GRDDL until I dealt with Drupal. It's another bloated as gently caress specification from the crazy loving people at W3C who, instead of doing useful things like un-loving the DOM or working on HTML5 have been doing batshit stuff like this. It's at least a dozen tags and a few namespaces that Drupal puts in for GRDDL stuff, poo poo that they don't even put in the drupal.org home page.
|
# ? Jan 30, 2011 07:57 |
|
Vanadium posted:< Vanadium> cout << std::abs(std::numeric_limits<int>::min()) MEAT TREAT posted:I would have preferred the function throw an exception rather than return a negative number. The original code looks like C# to me, in which case: it does (System.OverflowException). Bonfire Lit fucked around with this message at 14:34 on Jan 30, 2011 |
# ? Jan 30, 2011 14:29 |
|
Wanted to add a stemmer to a small program I'm writing. (A stemmer reduces words to their stem; "writing" becomes "write") Used Apache's modification of the generated Java version of the Snowball Porter2 stemmer. (Snowball code here) It worked fine, but then I decided to look at the Java code and The Snowball->Java compiler apparently writes everything as labeled while(true){} statements or do {} while (false); statements. code:
code:
|
# ? Jan 31, 2011 09:08 |
|
Treating generated code as anything other than an object file is a horror itself. You're not supposed to read it, so it's fine for a generator to make life easy on itself with stuff like do { ....} while (false) and whatever.
|
# ? Jan 31, 2011 10:03 |
|
Qwertycoatl posted:Treating generated code as anything other than an object file is a horror itself. You're not supposed to read it, so it's fine for a generator to make life easy on itself with stuff like do { ....} while (false) and whatever.
|
# ? Jan 31, 2011 10:37 |
|
code:
Paul MaudDib fucked around with this message at 06:26 on Feb 1, 2011 |
# ? Feb 1, 2011 02:55 |
|
the comments skip += blksize; //skip = skip + blksize
|
# ? Feb 1, 2011 03:15 |
|
Student code is usually bad. It's when someone's getting paid to write it that makes it really a horror. But that code is very bad.
|
# ? Feb 1, 2011 03:18 |
|
Well... at least the brackets and white space look nice?
|
# ? Feb 1, 2011 04:19 |
|
The indentation is wrong, so no.
|
# ? Feb 1, 2011 05:02 |
|
Plorkyeran posted:The indentation is wrong, so no. What, four spaces instead of a (8 space, as is right and proper) tab?
|
# ? Feb 1, 2011 05:29 |
|
pseudorandom name posted:What, four spaces instead of a (8 space, as is right and proper) tab? code:
|
# ? Feb 1, 2011 05:31 |
|
Hah. This rabbit hole doesn't end, does it?
|
# ? Feb 1, 2011 05:33 |
|
Paul MaudDib posted:...use of the continue statement... Unless I'm missing something here, the continue statement isn't a horror in principle. It's a very useful construct.
|
# ? Feb 1, 2011 09:35 |
|
Looks like a student that has been staring at assembly code for too long. Also explains the ... 'comments'
|
# ? Feb 1, 2011 10:53 |
|
Beef posted:Looks like a student that has been staring at assembly code for too long. Hah, yeah I just noticed one of their first programming courses was assembler and the other two were C, talk about your horrors to learn with.
|
# ? Feb 1, 2011 11:31 |
|
http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/
|
# ? Feb 1, 2011 16:55 |
|
I'm taking a numeric analysis course this semester, and the second chapter is literally all about floating point errors and bounds checking and how much this is going to gently caress you over and over until you get it right. Then we have languages like PHP and Java, who were apparently too good to learn that crap.
|
# ? Feb 1, 2011 17:20 |
|
NotShadowStar posted:I'm taking a numeric analysis course this semester, and the second chapter is literally all about floating point errors and bounds checking and how much this is going to gently caress you over and over until you get it right.
|
# ? Feb 1, 2011 18:29 |
|
ah, the simple joys of embedded coding. code:
|
# ? Feb 1, 2011 18:57 |
|
|
# ? Apr 27, 2024 14:23 |
|
zootm posted:As much as it should, I would be impressed if the chapter mentions the x87 weirdness that causes this particular issue. Whoever thought it would be a good idea that your value can change when it moves from a register to memory ought to be shot. I don't think that the Java problem is the same x87 weirdness as PHP. Their algorithm is different (approximating toward the target from the other direction), and also it seems to work (not work) on 32-bit and 64-bit hardware.
|
# ? Feb 1, 2011 19:25 |