Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Infinity and -Infinity

 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
float f = 5.0f/ -0 ;
results in + infinity, why not - infinity?
if I divide by -0.0f then the result is - infinity.
Can anyone explain this?
Thanks,
Vanitha.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vanitha,
I'm not 100% sure but I think it's because '-0' is an <code>int</code>. '0' is just zero to an integer type, + and - don't come into play. The value '0' would be promoted to <code>float</code> and the '-' sign is lost.
When you write '-0.0f' you are telling the JVM this is 'float'; and negative or positive zero is meaningful in floating point operations.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Vanitha Sugumaran
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jane,
Thanks for your reply. You are right. I tried this,
int integer = -0;
float floa = (float)(integer);
System.out.println("The value of integer is " + integer + "the value of float is " + floa);
//prints The value of integer is 0the value of float is 0.0
Now i got the point,
Vanitha.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javaranchers,

Regarding to Infinity & -Infinity .
I think relative Precedence of - (Unary) & / (Binary) will clear doubt about this Que.
When compiler will reaches to exp. 5.0f / -0; , It will consider �0 first and as There is no such -0 integral litral it will take it as 0.And then widening conversion will takes place.
i.e.
1) -0 ---> 0
2) 5.0f /0
3) 5.0f /0.0
will give + infinity.
Am I right ? Ple tell me . I m keen for reply.
Ketan Patel

------------------
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic