mirror of
https://github.com/holub/mame
synced 2025-07-04 17:38:08 +03:00
machine/rescap.h: Use constexpr where it won't change semantics.
The other function-like macros will invoke type decay or promotion depending on what the argument expressions evaluate to, so chaning them to constepr functions could change semantics.
This commit is contained in:
parent
20a7993c8b
commit
35b3515fe0
@ -4,19 +4,19 @@
|
|||||||
#define MAME_MACHINE_RESCAP_H
|
#define MAME_MACHINE_RESCAP_H
|
||||||
|
|
||||||
// Little helpers for magnitude conversions
|
// Little helpers for magnitude conversions
|
||||||
#define RES_R(res) ((double)(res))
|
constexpr double RES_R(double res) { return res; }
|
||||||
#define RES_K(res) ((double)(res) * 1e3)
|
constexpr double RES_K(double res) { return res * 1e3; }
|
||||||
#define RES_M(res) ((double)(res) * 1e6)
|
constexpr double RES_M(double res) { return res * 1e6; }
|
||||||
#define RES_INF (-1)
|
#define RES_INF (-1)
|
||||||
#define CAP_U(cap) ((double)(cap) * 1e-6)
|
constexpr double CAP_U(double cap) { return cap * 1e-6; }
|
||||||
#define CAP_N(cap) ((double)(cap) * 1e-9)
|
constexpr double CAP_N(double cap) { return cap * 1e-9; }
|
||||||
#define CAP_P(cap) ((double)(cap) * 1e-12)
|
constexpr double CAP_P(double cap) { return cap * 1e-12; }
|
||||||
#define IND_U(ind) ((double)(ind) * 1e-6)
|
constexpr double IND_U(double ind) { return ind * 1e-6; }
|
||||||
#define IND_N(ind) ((double)(ind) * 1e-9)
|
constexpr double IND_N(double ind) { return ind * 1e-9; }
|
||||||
#define IND_P(ind) ((double)(ind) * 1e-12)
|
constexpr double IND_P(double ind) { return ind * 1e-12; }
|
||||||
|
|
||||||
// vin --/\r1/\-- out --/\r2/\-- gnd
|
// vin --/\r1/\-- out --/\r2/\-- gnd
|
||||||
#define RES_VOLTAGE_DIVIDER(r1, r2) ((double)(r2) / ((double)(r1) + (double)(r2)))
|
constexpr double RES_VOLTAGE_DIVIDER(double r1, double r2) { return r2 / (r1 + r2); }
|
||||||
|
|
||||||
#define RES_2_PARALLEL(r1, r2) (((r1) * (r2)) / ((r1) + (r2)))
|
#define RES_2_PARALLEL(r1, r2) (((r1) * (r2)) / ((r1) + (r2)))
|
||||||
#define RES_3_PARALLEL(r1, r2, r3) (1.0 / (1.0 / (r1) + 1.0 / (r2) + 1.0 / (r3)))
|
#define RES_3_PARALLEL(r1, r2, r3) (1.0 / (1.0 / (r1) + 1.0 / (r2) + 1.0 / (r3)))
|
||||||
@ -28,13 +28,13 @@
|
|||||||
|
|
||||||
// macro for the RC time constant on a 74LS123 with C > 1000pF
|
// macro for the RC time constant on a 74LS123 with C > 1000pF
|
||||||
// R is in ohms, C is in farads
|
// R is in ohms, C is in farads
|
||||||
#define TIME_OF_74LS123(r,c) (0.45 * (double)(r) * (double)(c))
|
constexpr double TIME_OF_74LS123(double r, double c) { return 0.45 * r * c; }
|
||||||
|
|
||||||
// macros for the RC time constant on a 555 timer IC
|
// macros for the RC time constant on a 555 timer IC
|
||||||
// R is in ohms, C is in farads
|
// R is in ohms, C is in farads
|
||||||
#define PERIOD_OF_555_MONOSTABLE_NSEC(r,c) ((attoseconds_t)(1100000000 * (double)(r) * (double)(c)))
|
constexpr attoseconds_t PERIOD_OF_555_MONOSTABLE_NSEC(double r, double c) { return attoseconds_t(1100000000 * r * c); }
|
||||||
#define PERIOD_OF_555_ASTABLE_NSEC(r1,r2,c) ((attoseconds_t)( 693000000 * ((double)(r1) + 2.0 * (double)(r2)) * (double)(c)))
|
constexpr attoseconds_t PERIOD_OF_555_ASTABLE_NSEC(double r1, double r2, double c) { return attoseconds_t( 693000000 * (r1 + 2.0 * r2) * c); }
|
||||||
#define PERIOD_OF_555_MONOSTABLE(r,c) attotime::from_nsec(PERIOD_OF_555_MONOSTABLE_NSEC(r,c))
|
constexpr attotime PERIOD_OF_555_MONOSTABLE(double r, double c) { return attotime::from_nsec(PERIOD_OF_555_MONOSTABLE_NSEC(r, c)); }
|
||||||
#define PERIOD_OF_555_ASTABLE(r1,r2,c) attotime::from_nsec(PERIOD_OF_555_ASTABLE_NSEC(r1,r2,c))
|
constexpr attotime PERIOD_OF_555_ASTABLE(double r1, double r2, double c) { return attotime::from_nsec(PERIOD_OF_555_ASTABLE_NSEC(r1, r2, c)); }
|
||||||
|
|
||||||
#endif // MAME_MACHINE_RESCAP_H
|
#endif // MAME_MACHINE_RESCAP_H
|
||||||
|
Loading…
Reference in New Issue
Block a user