Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/Double.carp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
(register from-float (Fn [Float] Double))
(register to-long (Fn [Double] Long))
(register from-long (Fn [Long] Double))
(register to-uint64 (Fn [Double] Uint64))
(register from-uint64 (Fn [Uint64] Double))
(register to-bytes (Fn [Double] Long))
(register copy (Fn [(Ref Double)] Double))

Expand Down
2 changes: 1 addition & 1 deletion core/Random.carp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

(doc seed "seed resets the seed of the random number generator.")
(defn seed []
(set! s (Double.from-long (System.nanotime))))
(set! s (Double.from-uint64 (System.nanotime))))

(doc seed-from "seed-from resets the seed of the random number generator to `new-seed`.")
(defn seed-from [new-seed]
Expand Down
4 changes: 2 additions & 2 deletions core/System.carp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
(register carp-init-globals (Fn [Int (Ptr (Ptr CChar))] ()) "carp_init_globals")
(doc time "Gets the current system time as an integer.")
(register time (Fn [] Int))
(doc nanotime "Gets the current system time in nanoseconds as a long.")
(register nanotime (Fn [] Long))
(doc nanotime "Gets the current system time in nanoseconds as a uint64_t.")
(register nanotime (Fn [] Uint64))
(doc sleep-seconds "Sleeps for a specified number of seconds.")
(register sleep-seconds (Fn [Int] ()))
(doc sleep-seconds "Sleeps for a specified number of microseconds.")
Expand Down
8 changes: 8 additions & 0 deletions core/carp_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ double Double_from_MINUS_long(Long x) {
return (double)x;
}

uint64_t Double_to_MINUS_uint64(double x) {
return (uint64_t)x;
}

double Double_from_MINUS_uint64(uint64_t x) {
return (double)x;
}

double Double_abs(double x) {
return x > 0.0 ? x : -x;
}
Expand Down
6 changes: 3 additions & 3 deletions core/carp_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void System_sleep_MINUS_micros(int t) {
// TODO!
}

double System_nanotime() {
uint64_t System_nanotime() {
return 0;
}
#else
Expand All @@ -27,10 +27,10 @@ void System_sleep_MINUS_micros(int t) {
usleep(t);
}

double System_nanotime() {
uint64_t System_nanotime() {
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return 1000000000 * tv.tv_sec + tv.tv_nsec;
return (uint64_t)1000000000 * (uint64_t)tv.tv_sec + (uint64_t)tv.tv_nsec;
}
#endif

Expand Down
Loading