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);