This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with TensorFlow and have Chris A. Mattmann on-line!
See this thread for details.
Win a copy of Machine Learning with TensorFlow this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

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,
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic