• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Printing true

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static void main (String[] args) {
System.out.print(Integer.MIN_VALUE == Math.abs(Integer.MIN_VALUE));
}
1. Why the output is true for Integer,Long,Double,Float.
2. The abs() should strip -ve sign for Integer,Long,Double. i.e Math.abs(Integer.MIN_VALUE)
3.Why is it stripping off -ve sign only for Short and Byte.
4. What is the value of MIN_VALUE,MAX_VALUE for Float,Double.
Thanks
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suresh,
The API notes the following for Math.abs(Integer.MIN_VALUE)
.....Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.
Ditto for Long
As for Double & Float remember that Float.MIN_VALUE & Double.MIN_VALUE are positive values so you get the same result.
HTH
Ashish H.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Float.MIN_VALUE and Float.MAX_VALUE are positive??? Why they are not negative ???
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not from a CS background ( Chem actually ) so I really take the word of the API for granted , period.
I really don't know why the makers of Java did so.Maybe someone else here can enlighten us
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ August 28, 2002: Message edited by: Thomas Paul ]
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic