java - Is it possible to lose precision while calulating 1/val twice? -


if have double d; if do:

d = 1/d; d = 1/d; 

is possible lose precision? in case example?

yes, ofcourse it's possible loose precision. floating-point types such float , double not infinitely precise.

double d = 123456789.0;  system.out.println(d); d = 1 / d; d = 1 / d; system.out.println(d); 

output:

1.23456789e8 1.2345678899999999e8 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -