Skip to content

Commit 287cfb9

Browse files
committed
fix(core): fix System_nanotime cast from long to double to long
1 parent 3471bd3 commit 287cfb9

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

core/Double.carp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
(register from-float (Fn [Float] Double))
2222
(register to-long (Fn [Double] Long))
2323
(register from-long (Fn [Long] Double))
24+
(register to-uint64 (Fn [Double] Uint64))
25+
(register from-uint64 (Fn [Uint64] Double))
2426
(register to-bytes (Fn [Double] Long))
2527
(register copy (Fn [(Ref Double)] Double))
2628

core/System.carp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(register carp-init-globals (Fn [Int (Ptr (Ptr CChar))] ()) "carp_init_globals")
99
(doc time "Gets the current system time as an integer.")
1010
(register time (Fn [] Int))
11-
(doc nanotime "Gets the current system time in nanoseconds as a long.")
11+
(doc nanotime "Gets the current system time in nanoseconds as a uint64_t.")
1212
(register nanotime (Fn [] Long))
1313
(doc sleep-seconds "Sleeps for a specified number of seconds.")
1414
(register sleep-seconds (Fn [Int] ()))

core/carp_double.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ double Double_from_MINUS_long(Long x) {
6060
return (double)x;
6161
}
6262

63+
double Double_to_MINUS_uint64(double x) {
64+
return (uint64_t)x;
65+
}
66+
67+
double Double_from_MINUS_uint64(uint64_t x) {
68+
return (double)x;
69+
}
70+
6371
double Double_abs(double x) {
6472
return x > 0.0 ? x : -x;
6573
}

core/carp_system.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void System_sleep_MINUS_micros(int t) {
1515
// TODO!
1616
}
1717

18-
double System_nanotime() {
18+
uint64_t System_nanotime() {
1919
return 0;
2020
}
2121
#else
@@ -27,10 +27,10 @@ void System_sleep_MINUS_micros(int t) {
2727
usleep(t);
2828
}
2929

30-
double System_nanotime() {
30+
uint64_t System_nanotime() {
3131
struct timespec tv;
3232
clock_gettime(CLOCK_REALTIME, &tv);
33-
return 1000000000 * tv.tv_sec + tv.tv_nsec;
33+
return (uint64_t)1000000000 * (uint64_t)tv.tv_sec + (uint64_t)tv.tv_nsec;
3434
}
3535
#endif
3636

0 commit comments

Comments
 (0)