[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>work on a personal project in Java >notice arithmetics
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 27
Thread images: 3
>work on a personal project in Java
>notice arithmetics start to spew out shit at one point
>started debugging
>245 / 255 * 235 evaluates to 0 in Java
What the actual fuck?
>>
>>55327945
>2016
>sublime text
PLEB
L
E
B
>>
are you sure it's java and not just shitty intellisense?
>>
Poo in loo Rajeet.
>>
>>55327945
>why do I have to care about data types?!
Have you considered using Python or PHP? It tries to cater to your kind.
>>
>>55327945
>doesn't understand integer arithmetic
>blames it on java

WELCOME SUMMER

YOU MUST BE 18+ TO USE 4CHAN

GET THE FUCK OUT
>>
>>55327945
Moron
>>
>>55327945
install gentoo
>>
integer division friendo

245/255 floors to 0 and you can do the rest
>>
>>55328039
At least this is better than RX480 thread #90000
>>
>>55328078
I have those threads filtered though. You can't filter OP's kind of stupidity
>>
File: par72bb1[1].jpg (21 KB, 240x260) Image search: [Google]
par72bb1[1].jpg
21 KB, 240x260
>>55328078
it's about on par
>>
>>55327945
245/255 will be casted to 0 since it's an integer division.
>>
File: 1465007610498.png (533 KB, 500x525) Image search: [Google]
1465007610498.png
533 KB, 500x525
>>55328100
>casted
>>
>>55327945
so since you're an absolute fuckwit and have no experience in programming whatsoever, it'd be a dick move to not teach you something:
if you want to use a number as a float, you can use "245f" instead of 245 (similarly 245l will be long)
if you use 245.0, it is double
>>
>>55327945
Add .0 at the end of the numbers to make them floating-point.
>>
>>55327945
That is shit code and you don't understand what you're doing. I recommend you read a book, friendo
>>
>>55328155
>245f
is that typecasting?
>>
>>55328155
>>55328068
>>55328100
Thanks, got it now.
>>
>>55328217
No, that declares a float literal. A cast would be

(float)245
>>
>>55328217
not really. casting means taking one thing and making it something else. 245f just initializes that number to be float. There is never an integer representation of 245 made. But in a more semantic sense, you might call it casting
>>
>>55328068
>>55328100
>>55328155
Am I the only one that would fix this by changing it to 245 * 235 / 255 to keep the math integer based?
I guess AVR has changed me.
>>
>>55328323
Yes, because that still doesn't get the answer OP wants.
>>
>>55328323
this implies that OP actually wanted an integer back.
>>
>>55328346
>>55328367
OP didn't specify. I assumed he just wanted a non-zero answer
>>
>>55328410
If he's surprised by getting zero from that expression he clearly wanted a floating point answer.
>>
>>55328086
this
Thread replies: 27
Thread images: 3

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

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.