Version: 2008
  • On mySimon: Victoria's Secret Vanilla Orchid

Comments on: Why Java can't do addition correctly

A detour into nerdville to explain why Java can add two positive numbers and get a negative result. And, consider it the right answer.

Add a Comment (Log in or register) (3 Comments)
  • prev
  • 1
  • next
Sanitation Truck Collision
by tenc21 October 26, 2007 7:10 PM PDT
Dude, did you flip on your roller board into the side of a garbage truck? Not only is there a whole lot of garbage out there, it's a real mess and you added to the chaos with your attempt at explaining Java addition to the "general audience."

Assuming everything you say is true, what does any of that have to do with defensive computing? How does it affect the security of my gaming machine? So, Java can't add--does that mean my scores on all of my games are wrong? Sure, computers should compute. Windows should be secure. The world should be free of terrorists.

Get real, man...and don't forget the protective headgear when riding your board into the side of a truck! [defensive boarding, rule #1]
Reply to this comment
It's not Java
by davidsarmstrong October 28, 2007 11:43 AM PDT
The problem is a 32-bit word used in integer math. I get the same results using C on Linux. If you use the java.math package BigDecimal object you get the expected answer.
Reply to this comment
by petrakovichj June 1, 2009 8:51 PM PDT
Yeah there is no point in discrediting Java here, that's why it is called a 'strongly-typed' language. The programmer is responsible for choosing the right type. And to the above comment, you can just use a 'long', you don't need to use anything from a package.
Reply to this comment
(3 Comments)
  • prev
  • 1
  • next
advertisement

Google's mobile hopes go beyond Nexus One

The world may have thrilled to the potential for a Google Phone, but what Google actually unveiled is its plan for a new smartphone world order.
• Photos: Unboxing Nexus One

Using your smartphone safely

faq Worms, Trojans, and SMS attacks are risks for mobile phones, but the biggest practical threat to users is losing the device.

About Defensive Computing

Michael Horowitz is an independent computer consultant and the author of several classes on Defensive Computing. He views Defensive Computing as taking steps, when things are running well, to avoid or minimize the inevitable problems down the road. It's about educating yourself to the level where you can make your own intelligent decisions about keeping your computers and data happy and healthy. If you depend on computers, yet are on your own, without an IT department or nearby nerd, this blog's for you. His personal web site is michaelhorowitz.com.

He is a member of the CNET Blog Network and is not an employee of CNET.

Disclosure.

Add this feed to your online news reader

Defensive Computing topics

advertisement
advertisement