summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2018-11-06 13:39:13 +0100
committer hap <happppp@users.noreply.github.com>2018-11-06 13:39:13 +0100
commit60c4816861e7276096a2dfcb563b9bb79a3f293c (patch)
tree0364ba311881b83982ab1c49a978829d1f62440e
parent9df6cfe0870923fe2054ebe8e8f6ef081736831d (diff)
attotime: simpler from_hz (nw)
-rw-r--r--src/emu/attotime.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/emu/attotime.h b/src/emu/attotime.h
index 12fb43d1ef7..afd9cecbb32 100644
--- a/src/emu/attotime.h
+++ b/src/emu/attotime.h
@@ -137,10 +137,10 @@ public:
/** Create an attotime from a integer count of nanoseconds @nsec */
static constexpr attotime from_nsec(s64 nsec) { return attotime(nsec / 1000000000, (nsec % 1000000000) * (ATTOSECONDS_PER_SECOND / 1000000000)); }
/** Create an attotime from at the given frequency @frequency */
- static attotime from_hz(double frequency) { assert(frequency > 0); double d = 1 / frequency; return attotime(floor(d), modf(d, &d) * ATTOSECONDS_PER_SECOND); }
- static attotime from_hz(u32 frequency) { return from_hz(double(frequency)); }
- static attotime from_hz(int frequency) { return from_hz(double(frequency)); }
- static attotime from_hz(const XTAL &xtal) { return from_hz(xtal.dvalue()); }
+ static attotime from_hz(u32 frequency) { return (frequency > 1) ? attotime(0, HZ_TO_ATTOSECONDS(frequency)) : (frequency == 1) ? attotime(1, 0) : attotime::never; }
+ static attotime from_hz(int frequency) { return (frequency > 0) ? from_hz(u32(frequency)) : attotime::never; }
+ static attotime from_hz(const XTAL &xtal) { return from_hz(xtal.value()); }
+ static attotime from_hz(double frequency) { if (frequency > 0.0) { double i, f = modf(1.0 / frequency, &i); return attotime(i, f * ATTOSECONDS_PER_SECOND); } else return attotime::never; }
// math
attotime &operator+=(const attotime &right);