Re: [Rd] Double to uint64_t on M1

2021-08-12 Thread Prof Brian Ripley
On 12/08/2021 04:52, Simon Urbanek wrote: Dipterix, this has nothing to do with R. 2^63 is too large to be represented as singed integer, so the behavior is undefined - to quote from the C99 specs (6.3.1.4): "If the value of the integral part cannot be represented by the integer type, the be

Re: [Rd] Double to uint64_t on M1

2021-08-11 Thread Dipterix Wang
Thank you, I guess I should convert double to uint64_t instead of int64_t... The reason why I asked is because bit64 package `bit64::as.integer64(2^63)` produces different results on my machine vs. another server. This package converts double to int64_t directly. Looks like this is a bug in the

Re: [Rd] Double to uint64_t on M1

2021-08-11 Thread Simon Urbanek
Dipterix, this has nothing to do with R. 2^63 is too large to be represented as singed integer, so the behavior is undefined - to quote from the C99 specs (6.3.1.4): "If the value of the integral part cannot be represented by the integer type, the behavior is undefined." Your subject doesn't

[Rd] Double to uint64_t on M1

2021-08-11 Thread Dipterix Wang
Hi, I was trying to convert REALSXP to int64_t in C, then found that converting 2^63 is inconsistent across platforms: On M1 ARM osx, 2^63 (double) bit converting to `int64_t` becomes 9223372036854775807 On x86_64 ubuntu server, 2^63 (double) bit converting to `int64_t` is -92233720368547758