[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Advertisement | Home]

how to divide correctly

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 68
Thread images: 8

File: meme.png (1MB, 956x955px) Image search: [Google]
meme.png
1MB, 956x955px
bitshift op
>>
>>59482736
One of these things are different from the others.
>>
no it isnt. everything divides by 2.
>>
Real programming languages don't support bitshifting, thats just for autistic people lol
>>
>>59482761

Until you consider rounding errors.
>>
lol stfu highlevelfag
>>
>>59482778
because multiply/division is the only purpose of bit shifting : ^ )
>>
>>59482815
who said that?
>>
File: 1479916122212.jpg (10KB, 184x184px) Image search: [Google]
1479916122212.jpg
10KB, 184x184px
>>>59482815
Whats wrong autist? mad that you cant find a job where something like bitshifting is relevant ??
learn java like a normal person lol
>>
>>59482787
there aren't rounding errors where nothing cant be rounded.
>>
Most compilers optimize power of 2 divisions into bit shifts.

Doing actual bit-shifting in your code is autistic.
>>
>>59482895
>Most compilers
>>
>>59482736
If your compiler doesn't do that for you automatically it's shit
>>
>>59482778
>Real language
>Can't even use basic bitwise ops
HAHAHAHA what shit fucking garbage lang do you use? even fucking python has bit ops.
>>
>>59482913
you fucking CIA nigger i wrote my own compiler
the difference between a professional and a ammatuere is if you write your own compiler
>>
File: 1468140516062.jpg (51KB, 706x720px)
1468140516062.jpg
51KB, 706x720px
>>59482736
>>59482761
>>59482778
>>59482852
>>59482891
>>59482895

god damn shitheads. last one only works on integers.
>>
>>59482964
you nigger stop shittalking if you dont know
>>
File: i0Iy9Si.png (140KB, 636x410px) Image search: [Google]
i0Iy9Si.png
140KB, 636x410px
>>59482895
IKR fucking autists bro
>>59482913
Who even uses compilers in 2k17 ?? its like you dont want to have a job
>>59482930
LUA
>>
>>59482994
lua isnt a programming language
html is one.
>>
each of these may yield different values on same input
>>
>>59482736
>>1
what did he mean by this
>>
>>59482994
>LUA
https://www.lua.org/manual/5.3/manual.html#3.4.2
>>
>>59482994

>using an outdated version of Lua

So how's your roblox game coming along?
>>
>>59482852

Actually my job is exactly that.
>>
>>59482994
nice paste aspie
>>
>>59483024
>html
>programming language
Pick one
>>
>>59482994
>Who even uses compilers in 2k17 ?? its like you dont want to have a job
I'm a white man, I wrote my own fucking compiler, I'm not a nigger like Linus. I'm a professional, I started at Ticketmaster 1990 and we wrote a compiler, the difference between an amateur and a professional is you write your own compiler. I have a 20,000 line divine intellect compiler that operates just in time and ahead of time, you seem to be in denial.
>>
>>59483789
>>59482936
My CIA niggers
>>
>>59482778
What language doesn't support bitwise operations?
>>
>>59482736
Wouldn't division of an int by two just get compiled into a bitshift anyway?
>>
>>59484960
Yes. OP is retarded.
Any optimizing compiler will do this.
>>
>>59482905
sorry, i meant literally every compiler.
>>
What's the second one do?
>>
>>59485363
Mulitplies by a half, so the equivalent of dividing by 2.

Or did you mean something else?
>>
>>59485716
Why is the f there?
>>
>>59485874
so it's a float instead of double
>>
>>59485874
It's to tell the compiler that the number is a floating point number.
>>
>>59485889
>>59485911
Ah, right. Thanks.
>>
>>59482736
>Buttshifting floats.
>>
File: 1489951095970.png (804KB, 956x955px) Image search: [Google]
1489951095970.png
804KB, 956x955px
>>59482736
>>
>>59486272
where does n come from?
>>
>>59486335
end condition for a loop over n
>>
>>59486272
>x^0.5
>Using XOR
>any year
>>
>>59486272
What is n?
>>
>>59486352
template<typename T>
void swap(T &a, T &b)
{
a ^= b;
b ^= a;
a ^= b;
}

>inb4 sepples
>>
>>59482994
gamerfood is that you?
>>
>>59482736
How does this work?
>>
>>59486681
https://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_avoidance_in_practice
>>
File: Screenshot_2017-03-19-17-51-45.png (135KB, 720x1280px) Image search: [Google]
Screenshot_2017-03-19-17-51-45.png
135KB, 720x1280px
>>59482736
>>
>>59486774
https://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_use_in_practice
>>
>>59486934
>Because these situations are rare, most optimizing compilers do not generate XOR swap code.
>>
>>59483789
Shitposting aside, it seems like a really bad idea
to use it.
>>
>>59486841
>having bluetooth turned on
>browsing on phone
kys
>>
>>59486352
C has an exponent operator, didn't you know? Here, you can test it:
if (2^5 == 32)
if (3^3 == 27)
if (10^4 == 10000)
if (5^2 != 26)
if (4^3 != 8)
if (2^4 == 4^2) {
printf("exponentiation seems to be working just fine");
}
>>
>>59487582
Wow, I didn't know that! This'll make my code much cleaner.
>>
>>59487704
please don't
>>
>>59482778
Hot
>>
>>59482895
Im taking it you've never done embedded programming
because masking subroutines use bitshift
>>
>>59482964
>bit shifting a signed int
>>
>>59486841
This, people should focus on maintaining and improving modern compilers instead of worrying about autistic bit shifts.
>>
>>59482736
CL-USER> (/ 5 2)
5/2
CL-USER> (* 5 0.5)
2.5
CL-USER> (ash 5 -1)
2
>>
>>59482736
>doing the compilers job
autism
>>
>>59482736
Why don't they include tricks like these in compilers? Would a compiler turn divide by two for an integer into bitshift?
>>
File: dig-bick.jpg (51KB, 800x800px) Image search: [Google]
dig-bick.jpg
51KB, 800x800px
>>59490054
>5/2
>>
>>59490054
>Better solutions descending in C
>Better solutions ascending in CL
Really gets the old noggin joggin'.
>>
>>59482736
Not if you're using Javascript


Speaking of numbers, all numbers are 64-bit, except if you plan to do
any bitwise operation at all, in which case they're silently converted
to 32 bits, than back to 64 again:

Math.pow(2,31) == 2147483648 // true, as expected
1 << 31 == -2147483648 // also true, because fuck you
>>
>>59484960
>>59484983
Only if it's a literal or constant.
>>
>>59490356
What makes you think they don't?

I'd assume it would be a reasonable optimization to expect.
Thread posts: 68
Thread images: 8


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.