Unable to load image

Are you a C++ Chad?

After having my abilities been questioned by @iStillMissEd , i decided to create a little test to separate the chads from the chaff.

Here's a small snippet of c++ code:

bool function1(int8_t a, int8_t b)

{

int8_t aneg=-a;

int8_t bneg=-b;

return((a<b)==(aneg>bneg));

}

Describe when and why this function returns true. Best answer gets 250DC. No answer and you will be known as a javargin. !codecels

38
Jump in the discussion.

No email address required.

There wasn't a lot of substance to this problem , so here is what I expected you to realize. It looks like most of you didn't make it past :marseyretard: <-r-slur . !codecels get in!

  • :marseyretard2: you know the code is a valid c++ function

  • :marseybrainlet: you know the negation and comparison operator

  • :!marseycrayoneater: you know what int8_t is

  • :marseyretard: you know this should be true in general

  • :marseysmoothbrain: you know that this problem is dependent on the signed number representation

  • :marseyautism: you know that two's complement is the one you can expect

  • :marseyspecial: you know two's complement cannot be negated without potentionally causing overflow (0-INT_MIN>INT_MAX)

  • :marseyneko: you know this programm will run into UB but in practice return false if one of the inputs is int8_min (-128)

  • :marseyrick: you know this programm will run into UB but in practice return true if both inputs are int8_min (-128)

  • :marseybigbrain: you realize that c++ is bullshit anyway

Next time we will look into compile time meta programming using partial template specialization and SFINAE ofcourse :marseycapygigabrain:!

Jump in the discussion.

No email address required.

:marseywords:

wake me up when c++ is good

Jump in the discussion.

No email address required.

You're going to be a vegetable for the rest of your natural life:marseysleep:

Jump in the discussion.

No email address required.

The future is female that's why c++ has to go

Jump in the discussion.

No email address required.

:marseyclappingglasses:

C++ is based

Jump in the discussion.

No email address required.

I got to :marseyspecial: before i realized id been staring at my phone at my desk for a few minutes instead of actually working on my code

Jump in the discussion.

No email address required.

I'm surprised the compiler doesn't optimize it away return true

Jump in the discussion.

No email address required.

I only code in forth

Jump in the discussion.

No email address required.

So when do I get my coins?

Jump in the discussion.

No email address required.

Just send you 100 coins! you didn't expand on the expected results the function will return( despite running into UB). So no perfect answer! take it or leave it :marseyindignant:

Jump in the discussion.

No email address required.

Expected result my butt. For all you know this code formats your disks. I should get extra coins for pointing that out to you and saving you the trouble of restoring a backup.

Jump in the discussion.

No email address required.

show me a compiler where this isn't the case and only then ill rethink my position :marseyindignant:

Jump in the discussion.

No email address required.

how many points did chatgpt get

Jump in the discussion.

No email address required.

:marseyautism: you know that two's complement is the one you can expect

it didnt realize negating a twos complement can run into UB

Jump in the discussion.

No email address required.

I haven't used C++ since college but isn't this literally an identity?

3 < 5 so -3 > -5

Jump in the discussion.

No email address required.

This is the brainlet answer. :marseybrainlet::marseylaugh:

I saw your upvote @iStillMissEd. IT NEVER EVEN BEGAN FOR YOU.

Jump in the discussion.

No email address required.

how is this the brainlet answer? is there some r-sluration of c++ that I'm missing?

Jump in the discussion.

No email address required.

is there some r-sluration of c++ that I'm missing?

Do you really have to ask this?

Jump in the discussion.

No email address required.

yes!i will edit the answer in tomoroow.

Jump in the discussion.

No email address required.

Oh I thought you were asking "why does this function return true" :marseybrainlet:

Jump in the discussion.

No email address required.

I saw your upvote @iStillMissEd. IT NEVER EVEN BEGAN FOR YOU.

>implying i read what I vote on

Jump in the discussion.

No email address required.

Yeah.

Jump in the discussion.

No email address required.

C++ is for people who like wasting their time.

Jump in the discussion.

No email address required.

:marseyagreesuperspeed:

Jump in the discussion.

No email address required.

Real men use D and java

Jump in the discussion.

No email address required.

Java is for sexy Indian dudes.

Jump in the discussion.

No email address required.

undefined behaviour, because if the argument is -128 the negative is undefined. Add a check for that and it returns true.

Jump in the discussion.

No email address required.

This is correct. And today I learned that C++20 banned sign-magnitude and one's complement representations, which used to be a way for this not to be undefined behavior

Jump in the discussion.

No email address required.

C++ is the DMV of programming languages.

Jump in the discussion.

No email address required.

This has always been undefined. I mean there's literally not enough space in 8 bits to do -INT8_MIN so unless you want to cut off bits like in casting it's nonsense. Which they do for unsigned I guess but it's always been understood those are different afaik.

Jump in the discussion.

No email address required.

In those other representations a signed 8 bit integer has a range -127 to 127 with positive and negative zeros.

Jump in the discussion.

No email address required.

>positive and negative zeros

:marseyyikes:

Jump in the discussion.

No email address required.

Interesting. Didn't know that was ever allowed.

Jump in the discussion.

No email address required.

it's not undefined behavior unless the function is actually called with -128 as an argument. If that doesn't happen then it's correct and always returns true

Jump in the discussion.

No email address required.

If the compiler's half decent this will be optimized down to mov eax, $1

Jump in the discussion.

No email address required.

yeah

Jump in the discussion.

No email address required.

I'm not moving my finger for 250dc you fricking poorcel :marseyindignant:

Jump in the discussion.

No email address required.

:marseypirate: : Argh, ye scurvy dog! I'll make ye walk the plank fer talkin' like that ta yer captain! 250 gold coins is me price an' ye best be gettin' it ta me quick if ye know what's good fer ye!

Jump in the discussion.

No email address required.

Arrrr

Jump in the discussion.

No email address required.

:marseypirate: : Yer a scurvy landlubber, ye are! Yer not fit to walk the plank, let alone be a pirate captain! I'll have ye know I've sailed the seven seas, and I've never met a more worthless bilge rat than yerself! Arrrr!

Jump in the discussion.

No email address required.

It's always planks with you...

Jump in the discussion.

No email address required.

:marseypirate: : Arrr, it's always planks with ye, is it? Well, let me tell ye, it's always gold with me! Gold, I tell ye! Arrrr!

Jump in the discussion.

No email address required.

Here is the online compiler I used: https://www.onlinegdb.com/online_c++_compiler

#include <iostream></iostream>

using namespace std;

bool function1(int a, int b) {

int aneg = -a;

int bneg = -b;

return ((a<b)==(aneg>bneg));

}

int main()

{

cout<<function1(1,2)<<endl;

cout<<function1(2,2)<<endl;

cout<<function1(-1,2)<<endl;

cout<<function1(1,-2)<<endl;

cout<<function1(-1,-2)<<endl;

cout<<function1(2,1)<<endl;

cout<<function1(-2,-2)<<endl;

cout<<function1(-2,1)<<endl;

cout<<function1(2,-2)<<endl;

cout<<function1(-1,-2)<<endl;

return 0;

}

All of these return true. Yeah I didn't use your gay butt int8_t because I don't see why using a signed 8 bit value matters in this case unless you want to pull that char trickery, and frankly using int8_t for a char is fricking stupid.

This doesn't really test C++ skill but instead it tests a person's understanding of math and it's a horrible example.

You proved @iStillMissEd 's point for us.

I think you owe me 500dc for the following reasons:

  1. I don't know any code at all. I googled really quick and copy and pasted this stuff

  2. I googled wtf an int8_t is. I'm not mathematically illiterate so I know what a signed value is. They mentioned the char for int8_t here:

    https://stackoverflow.com/questions/17744226/int8-t-vs-char-which-is-the-best-one

  3. I still managed to figure this out when I know nothing about your stupid computer language. Which means your test proves nothing about knowing C incremented by 1.

NOW PAY ME CUTE TWINK!

Jump in the discussion.

No email address required.

wrong, you didnt even grasp the problem.

its about the edge case surrounding its minimum limit. which is -128 for int_8t.

Jump in the discussion.

No email address required.

Hey guys! This genius thinks edge cases involving integer overflow only happens in C++.

Again, that is not C++ specific.

What's it like knowing a non codecel can show that your cutesy problem isn't specific to your pet language.

Jump in the discussion.

No email address required.

blablablah stop being a meanie and start having fun :marseybeandefiant:

Jump in the discussion.

No email address required.

Where is my 500DC?

Jump in the discussion.

No email address required.

based

Jump in the discussion.

No email address required.

Yeah it works for all the brainlet test cases, why, did you want an answer that won't break everything when you put in a weird number? :marseyfugg: what do you mean computers don't treat numbers the same way that math majors do?

Jump in the discussion.

No email address required.

Hey another genius that thinks integer overflow is C++ specific

Jump in the discussion.

No email address required.

Many languages have integer overflow, but none are based enough to have as much undefined behavior as C and C++

Jump in the discussion.

No email address required.

Your pulitzer's in the mail

Jump in the discussion.

No email address required.

It's some bullshit and it returns true because of some bullshit

3 different input modes:

a<b returns true because both conditions are true

a>b returns true because both conditions are false

a==b returns true because both conditions are false

Jump in the discussion.

No email address required.

That function makes you a kissless virgin op

Jump in the discussion.

No email address required.

:#marseylovedrama:

Jump in the discussion.

No email address required.

what does this have to do with c++ its just a==b

Jump in the discussion.

No email address required.

Reported by:

This function returns true when the inequality relationship between 'a' and 'b' is the same as that between their negations, '-a' and '-b'. In other words, if 'a' is less than 'b', then '-a' must be greater than '-b' and vice versa.

The function compares the two input values 'a' and 'b' and their negations 'aneg' and 'bneg'. It returns true if both comparisons yield the same result.

This occurs when:

1. 'a' and 'b' have the same sign (both positive or both negative), and their relative order remains the same after negation.

2. 'a' and 'b' have different signs, but the absolute value of 'a' equals the absolute value of 'b'. In this case, their relative order remains the same after negation.

Jump in the discussion.

No email address required.

Is this some dumbshit with int8_t being nothing more than a typedef of signed char.

Jump in the discussion.

No email address required.

Nothing more?:marseyraging:

Int8_t is THE internationally standardised typedef for char. An international committee spent weeks to get us that typedef, you should be happy.

Jump in the discussion.

No email address required.

:marseypirate: : Argh, ye landlubber! Ye think ye know everything about typin', just because some committee spent a few weeks on it? I've been at sea for years, and I know that int8_t is not the only typedef for char - there's also signed char and unsigned char. So don't be tellin' me what's what, or I'll make ye walk the plank!

Jump in the discussion.

No email address required.

What's the problem?

Jump in the discussion.

No email address required.

Writing code that is purposely r-slurred is /g/ tier autism. Attempting to compile this garbage should lead to the :marseyglow: being contacted and prison time.

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/16798772861903512.webp


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

i dont get it :marseyretard2:

Jump in the discussion.

No email address required.

>doesn't know keith

!codecels buck break this man


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

Keith is the c++ mascot. It's an elitist thing, c++ masochists think they're better than people who don't want to waste their time manually handling memory when memory is cheap as shit are making fun of most modern languages having cute mascots so they made theirs a diseased rat, probably because it was the healthiest animal in their room, including themselves.


:#marseytwerking:

:marseycoin::marseycoin::marseycoin:
Jump in the discussion.

No email address required.

The correct answer is that he should have written it in rust

Jump in the discussion.

No email address required.

Don't use bloated webshit languages, problem solved

Jump in the discussion.

No email address required.

It returns seethe cuz that's what this stack overflow copy and paste is.

Post some real code

Jump in the discussion.

No email address required.

Never call me a stackiverflowcel again :marseyraging: , i made it myself

Jump in the discussion.

No email address required.

True as long as -a and -b are both representable in an int8_t without underflow/overflow, right? I don't think this behavior was even defined until... 17? Whenever two's complement became required.

Jump in the discussion.

No email address required.

false iff one input is -128 and the other isn't, because the "negative" of min value -128 is still -128

https://en.wikipedia.org/wiki/Two%27s_complement#Most_negative_number

int8_t min = INT8_MIN;
int8_t minus_min = -INT8_MIN;
printf("%i %i\n", min, minus_min);  // Prints -128 -128, i.e. the - does nothing.
Jump in the discussion.

No email address required.

Bro you just invoked undefined behavior. You can't just say that the answer is what probably every compiler and computer outside of a museum will actually do, because the specification says it's undefined behavior. UNDEFINED

Jump in the discussion.

No email address required.

I forgot how r-slurred C++ typing is.

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

the catch is int8_t and I can only guess when a and b both are under 2^8/2 = 128

WHITE EXTINCTION IS LONG OVERDUE

Jump in the discussion.

No email address required.

It returns true when a and b have opposite signs (one is positive and the other is negative), and their absolute values are different.

Jump in the discussion.

No email address required.

:marseybaited#:

Jump in the discussion.

No email address required.

Imagine not knowing the IEEE float spec by heart 😂😂

and also not knowing the language specific float implementation details for every language an outsourced sexy Indian dude tech interviewer might throw at you

lol, lmao

Jump in the discussion.

No email address required.

In haskell this is just

function1 = ap (ap . ((&&) .) . (<)) (flip ((<) . negate) . negate)

and doesn't contain undefined heaviour since bignum is the default

Jump in the discussion.

No email address required.

>haskell

:marseyyikes:

Jump in the discussion.

No email address required.

:marseyno:

Jump in the discussion.

No email address required.

Bruh. isn't it

>int8_t aneg=-a;

I think this is cast into int because int8_t for reasons. Which causes problems but otherwise. You have negative values on aneg , bneg and postive values on a,b. if

If abneg will also be true since. Say you put in 1,2 then it's (1<2) == (-1>-2).

Jump in the discussion.

No email address required.

Reported by:

This function returns true when the two input values a and b have opposite signs (i.e., one is positive and the other is negative).

The function first negates the values of a and b using the unary minus operator and stores them in aneg and bneg variables, respectively.

Then it compares the original values a and b using the less-than operator < and compares the negated values aneg and bneg using the greater-than operator >.

The function returns true if and only if both comparisons yield the same result. In other words, if a is less than b, then aneg must be greater than bneg for the function to return true, and vice versa.

The reason for this behavior is that the sign of a signed integer is represented by the most significant bit (MSB) of its binary representation. If two integers have opposite signs, their MSBs will be different. Negating a number flips all its bits and adds one to its two's complement representation, effectively changing its sign. Therefore, if a is less than b, then aneg must be greater than bneg for their signs to match and vice versa.

Jump in the discussion.

No email address required.

C++ syntax is peepeepoo

Jump in the discussion.

No email address required.

Why do you pass by value?

Jump in the discussion.

No email address required.

it's a fricking char are you r-slurred?

Jump in the discussion.

No email address required.

Why would you not?

Jump in the discussion.

No email address required.

Because it's better (though negligible in this case). And it might help people to remember doing it when working with objects.

Jump in the discussion.

No email address required.

If the compiler doesn't inline the call, then the pass-by-value version of this function is faster since it's better to pass the int8_ts on cpu registers than it is to pass pointers to them and dereference them.

Jump in the discussion.

No email address required.

:marseypirate: : Argh, ye scurvy landlubber! Ye be knowin' nothin' 'bout the ways of the sea! If'n the compiler be wantin' to inline the call, then it'll do so, an' there'll be no difference in speed! But if'n it be choosin' not to inline the call, then the pass-by-reference version o' the function be faster, since ye be havin' to pass fewer pointers around!

Jump in the discussion.

No email address required.

The ways of the sea... more like the ways of the C, amirite?? :roflmao::roflmao:

But anyways, beebs, babe, this is clearly wrong. Haven't you programmed C++ before? Any pirate should know this.

Jump in the discussion.

No email address required.

:marseypirate: : Ye be wrong, scallywag! Any pirate worth their salt knows the ways of the sea, and there be no comparison to the ways of the C. Argh!

Jump in the discussion.

No email address required.

Well, I suppose I can't argue with that

Jump in the discussion.

No email address required.

:marseypirate: : Well, I suppose I can't argue with that, ye scurvy landlubber! This be the Captain speaking, and I'll have no such insolence on me ship! Now, get back to scrubbing the decks or I'll have ye walking the plank!

Jump in the discussion.

No email address required.

reference are basically pointers, that are basically stored in 64bit, why would that be better than passing an char to the function?

Jump in the discussion.

No email address required.

even if they weren't, manually using pointers won't help even for big data types as the compiler will do this for you regardless

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.