Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.abs() question

 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements are true in terms of the java.lang.Math.abs method?

a. Four overloaded versions of abs exist.
b. An ArithmeticException is declared in the throws clause.
c. The type of the return value depends on the argument type.
d. The returned value is always of a floating-point primitive type.
e. If the argument is a negative integral value, then the returned value is always positive.
f. If the argument is positive, then the argument is returned.


the answers are: a,c,f
But I think e could be true.
Why e is not one of answers?

Thanks.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why

Math.abs(Integer.MIN_VALUE); // This will return -2147483648

The issue is discussed here
 
Vicky Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Math.abs(Integer.MIN_VALUE); // This will return -2147483648


I think this is only case where the abs() method returns the negative value.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vicky Jain:
I think this is only case where the abs() method returns the negative value.

There are TWO cases in which abs will return -ve value
  • Math.abs(Integer.MIN_VALUE);
  • Math.abs(Long.MIN_VALUE);


  • For more info about the abs methods you can always read the API Documentaion here
    [ September 02, 2004: Message edited by: Vicken Karaoghlanian ]
     
    Vicky Jain
    Ranch Hand
    Posts: 52
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Vicken,

    Now i got it and thanks for correcting me man!!

    Bartenders may please close this topic.!

    Thanks
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic