You are not logged in. Please login at www.codechef.com to post your questions!

×

Precision Comparison of C++ 11 atan2 and Java 8 Math.atan2

Hi All,

There was two different solution one written in c++, other in Java. both using Standard library atan2 function.
Problem : http://codeforces.com/contest/598/problem/C
c++: http://codeforces.com/contest/598/submission/20762399 status : AC
java: http://codeforces.com/contest/598/submission/31950657 status : Failed on test 127

There are only 3/4 AC in java which uses BigDecimal. Is there is any difference in standard atan2 function in Java & c++ ? if yes, is there any other way to handle precision without using BigDecimal.

Thanks in Advance.

asked 01 Nov '17, 18:47

joney_000's gravatar image

4★joney_000
7928
accept rate: 0%

edited 01 Nov '17, 18:50


That's odd... the AC code above gives WA when I run it: nXndu1
However all other accepted C++ solutions I found differ from your Java solution in that they use long double and not double. The difference is not in the library functions but in the datatypes used. long double has better precision and that's probably the reason it gets AC. Since there is no long double type in Java, I suppose BigDecimal is the only way out.

link

answered 01 Nov '17, 20:07

meooow's gravatar image

6★meooow ♦
7.1k718
accept rate: 48%

edited 01 Nov '17, 20:09

java long is equivalent long double in cpp. REF: double IEEE 754 floating point ( 64 bits 1.23456e300d, -1.23456e-300d, 1e1d )

(01 Nov '17, 21:03) joney_0004★
1

No it's not. If you see the Wikipedia link I have provided it says

As with C's other floating-point types, it may not necessarily map to an IEEE format.

And also

With the GNU C Compiler, long double is 80-bit extended precision on x86 processors regardless of the physical storage used for the type (which can be either 96 or 128 bits).

So long double uses 80 bits whereas double uses 64 bits.

(01 Nov '17, 21:18) meooow ♦6★

In java for storing real numbers of large length , I think only BigDecimal is available.

link

answered 01 Nov '17, 20:58

spp____'s gravatar image

2★spp____
1.1k211
accept rate: 9%

yes, It's solvable by BigDecimal, are there is other ways to handle it with 8Byte double variable in Java.

(01 Nov '17, 21:05) joney_0004★

I am not sure but I think for this only BigDecimal works

(01 Nov '17, 21:15) spp____2★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×682
×73
×25
×13

question asked: 01 Nov '17, 18:47

question was seen: 511 times

last updated: 01 Nov '17, 21:19