majorexception | 1 year ago | on: `find` + `mkdir` is Turing complete
majorexception's comments
majorexception | 2 years ago | on: Improving our safety with a physical quantities and units library
temperature.in<si::Celsius>()majorexception | 2 years ago | on: Improving our safety with a physical quantities and units library
auto
operator"" _rpmPerVolt (long double x) {
return decltype (1_rpm / 1_V)(x);
}
I have a macro for that: #define SI_DEFINE_LITERAL(xUnit, xliteral) \
[[nodiscard]] \
constexpr Quantity<units::xUnit> \
operator"" xliteral (long double value) \
{ \
return Quantity<units::xUnit> (value); \
} \
\
[[nodiscard]] \
constexpr Quantity<units::xUnit> \
operator"" xliteral (unsigned long long value) \
{ \
return Quantity<units::xUnit> (value); \
}
// Base SI units:
SI_DEFINE_LITERAL (Meter, _m)
SI_DEFINE_LITERAL (Kilogram, _kg)
SI_DEFINE_LITERAL (Second, _s)
SI_DEFINE_LITERAL (Ampere, _A)
SI_DEFINE_LITERAL (Kelvin, _K)
SI_DEFINE_LITERAL (Mole, _mol)
SI_DEFINE_LITERAL (Candela, _cd)
SI_DEFINE_LITERAL (Radian, _rad)
...and a loong list of other common units here.The additional types are defined like this, in another file:
using Foot = ScaledUnit<Meter, std::ratio<1'200, 3'937>>;
using Mile = ScaledUnit<Meter, std::ratio<1'609'344, 1'000>>;
using NauticalMile = ScaledUnit<Meter, std::ratio<1'852, 1>>;
using Inch = ScaledUnit<Meter, std::ratio<254, 10'000>>;
And then I use SI_DEFINE_LITERAL (NauticalMile, _nm); etc.majorexception | 2 years ago | on: Improving our safety with a physical quantities and units library
majorexception | 2 years ago | on: Improving our safety with a physical quantities and units library
I can do things like:
si::Length length = 15_m + 12_nm; // _nm for Nautical Miles
si::Area area = 1_m * 1_km; // Equals to 1000_m2
si::Power power = 1_m / 1_sec / 1_sec; // Compilation error, 1_m/s² is not a si::Power
I don't have every possible User-Defined Literal, of course, so I end up doing this for less common units: using SomeLocalTypeName = decltype(1_rpm / 1_V);
Something to thing about, when designing such library:* What is 0_degC + 1_degC? 1_degC or… 273.15_K + 274.15_K = 547.3_K = 274.15_degC? I forbid operations between units if any of them has Offset parameter different than 0. I'm not sure if this is the good solution, though.
* Nm (Newton-meters) is the same unit as Joules. ;-)
majorexception | 7 years ago | on: Show HN: 300k lines of Java UI code running native in browser at desktop speed
On Firefox it's even worse, looks like it was rendered by 4 MHz Apple II. :|
But if it allows easy porting of a Java app to a browser, then this is still great stuff. Not the most responsive UI, but in case of emergency, why not?
Maybe it all boils down to how CPUs work, and maybe it's safe to say that the incompleteness comes from the CPU implementation? You can of course argue that Python interpreters are written in C/C++, but of course we can imagine they can be written in assembly.
Edit: after I read some other comments I think I see the point - that indeed the problem is the implementation (on CPU).