• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.abs()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,
This method is overloaded to take int,long,double,float argument. If the argument is Long.MIN_VALUE then compiler gives the following error.
A1.java:3: integer number too large: -9223372036854775808
System.out.println(Math.abs(-9223372036854775808));
^
He is an example,

What am I missing here?
Thanks,
Asha
Edited by Corey McGlone: Added CODE Tags.
[ February 02, 2004: Message edited by: Corey McGlone ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it isn't the abs method that is producing the error. The problem is that, in Java, any numeric literal, including -9223372036854775808, is interpreted as an integer. Obviously, that number doesn't fit into an integer.
Therefore, if you want that line to compile properly, you need to let the compiler know that this number is a long, not an integer, like this:

Notice the 'l' on the end of that number (that's a lower case L in case you can't see it well)? That let's the compiler know that it should interpret this value as a long, not an int. Do that, and your code will work fine...sort of.
You might want to see the resulting value and make sure you can explain that...
 
Asha Furtado
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it.
Thanks,
 
reply
    Bookmark Topic Watch Topic
  • New Topic