BINARYIO - Binary Input and Output

no tags 

Your task is to compute natural logarithm for real parameter X with absolute or relative error less than 10-12.

Input

Array of doubles in binary format (use fread in C/C++)

10-12 ≤ X ≤ 1012. There will be up to 1,000,000 numbers in array.

Output

Array of doubles in binary format (use fwrite in C/C++)

For each number in input you should output the corresponding answer.

Example

Input:
1
10

Output:
0
2.3025850929940456840179914546844

Note: Sample input and output are readable for your convenience!!!

Arrays in memory and in input are byte-to-byte identical.

To read double a use fread(&a, sizeof(a), 1, stdin) instead of scanf("%lf", &a) until the end of file.

To write double a use fwrite(&a, sizeof(a), 1, stdout) instead of printf("%lf\n", a).


hide comments
moudud: 2023-09-08 08:07:11

What is meant by array of doubles in binary format? What should I output for negative values?

Francky: 2013-03-01 18:44:04

I tried both methods to read (whole input, or double by double)... It works at home... Any clue for WA here ? Thanks.
ans: You should read/write array of doubles instead of long doubles. I think I made it clear in the statement. Do you think if I just use code like this:
union {double a[N]; long double b[N];};
or this
double a[N]; long double *b = (long double *)a;
then a[k] and b[k] will contain the same values?(The answer is NO)
--
Now I understand something :
The file is full of (double), we have to read them as (double). And then 'build' (long double) with two (double) that, in place, represent a (long double).
If it's that, I don't know how to do that. Is 'union' the magic word ?
---
1)I did't say a word about long double in the whole task.
2)Just google 'union c++'
--Fr--> OK, I don't know why I was focused on long double... And now I have AC without 'union'. lgamma is waiting for me...
Thanks for patience.

Last edit: 2013-03-01 20:54:51
Mitch Schwartz: 2013-03-01 18:36:26

Ohhh, no bit strings at all, now I understand.

Mitch Schwartz: 2013-03-01 18:36:26

I haven't done extensive bugtesting, but the question is a little unclear because it does not specify bit order; I'm using Wikipedia convention:

3ff0 0000 0000 0000 in hex (00111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 in binary) signifies 1

Is this the intended order?

Also, the bit strings in the actual input and output should be without spaces I assume?

Last edit: 2013-03-01 18:03:52

Added by:Michael Kharitonov
Date:2013-03-01
Time limit:0.100s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All