×

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

 0 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 79●2●8 accept rate: 0%

 1 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. answered 01 Nov '17, 20:07 6★meooow ♦ 7.1k●7●18 accept rate: 48% 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) 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★
 0 In java for storing real numbers of large length , I think only BigDecimal is available. answered 01 Nov '17, 20:58 2★spp____ 1.1k●2●11 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) I am not sure but I think for this only BigDecimal works (01 Nov '17, 21:15) spp____2★
 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:

×682
×73
×25
×13

question asked: 01 Nov '17, 18:47

question was seen: 511 times

last updated: 01 Nov '17, 21:19