×

# Range overflow in VSN

 2 When we are finding distance b/w P and Q (x2-x1)^2 + (y2-y1)^2 whole underoot.(for 2d case). Now according to constraint of co-ordinates (this value (x2-x1)^2 + (y2-y1)^2) can exceed max value possible to store)? asked 12 Jun '18, 00:00 21●1 accept rate: 0% 1 Its guaranteed that co-ordinates of Q never exceed $2*{10}^{9}$ during entire time. (12 Jun '18, 15:43)

 0 As specified in the constraints that the absolute value of the coordinates can be at max 2 10^9 . Now if we take x2=2 10^9, x1=-2 10^9, y2=2 10^9, y1=-2 *10^9, so it's pretty clear the value (x2-x1)^2 + (y2-y1)^2 turns out to be 32 *10^18 which does not fit into long type integers . So yes, it would overflow. answered 12 Jun '18, 15:50 121●7 accept rate: 6% Use long double. (12 Jun '18, 15:52) @vijju123 What about JAVA , it can support at max 64 bits (12 Jun '18, 15:55) Will double not suffice? Did you try that? (12 Jun '18, 18:47) @vijju123 no need to use long double, even for C++ double would suffice. (12 Jun '18, 18:53) sorb19974★ yeah @vijju123 and @souradeep1999 you are right (12 Jun '18, 19:04) Thats true, but long double afaik is more precise than double. I never trust floating points so thought better safe than sorry xD (12 Jun '18, 19:46) How can long double store more than 64 bits i.e >10^18 (13 Jun '18, 10:12) showing 5 of 7 show all
 0 As that is 64 bit then i think it can also store same as c++ upto 2^64-1,thats nearly 18*10^18. answered 12 Jun '18, 18:32 95●5 accept rate: 3%
 0 long double or even double can be used. They have a huge range (around $1.7e^{308}$) (check here) even though they are 64 bits since they use floating point representation, i.e. have some bits reserved for exponent and some bits for mantissa. answered 13 Jun '18, 16:45 0 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×316

question asked: 12 Jun '18, 00:00

question was seen: 527 times

last updated: 13 Jun '18, 16:45