From d|pter|x@w@ng @end|ng |rom gm@||@com  Thu Aug 12 00:50:17 2021
From: d|pter|x@w@ng @end|ng |rom gm@||@com (Dipterix Wang)
Date: Wed, 11 Aug 2021 18:50:17 -0400
Subject: [Rd] Double to uint64_t on M1
Message-ID: <EE649952-4BB6-432A-B3CA-BD9B11DD9324@gmail.com>

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 -9223372036854775808

I was wondering if this is desired behavior to R?

Here's the code to replicate the results above.

print_bit <- Rcpp::cppFunction(r"(
SEXP print_bit(SEXP obj){

  int64_t tmp1 = *REAL0(obj);
  printf("%lld ", tmp1);

  return(R_NilValue);
}
)")

print_bit(2^63)

Thanks,
- Dipterix
	[[alternative HTML version deleted]]



[Rd] Double to uint64_t on M1
Dipterix Wang