Closed AdamNorberg closed 3 years ago
The merge, of course, should be a squash commit, nobody really cares about the 40 commits I made along the way. Pretty much every time I save the file, I commit to my working branch with notes on what I did so I can roll back if/when I screw up.
Done. Added copy constructor, comment on GetHashCode
, explicit casts away from float
(the cast to double
is optional but the cast to decimal
is indeed required), and a single missing period. Thanks for the review! Anything else?
Whoops! I messed up my true
and false
operator implementations - I got them backwards, and I failed to add the NaN check I needed. Fixed.
Oh dear, well spotted! I completely overlooked that as well, thinking you were going for the 0=true model I've seen some embedded projects use.
I'll do another quick review of the changes you made.
I've added the integer-typed constructors, cast-in operators (implicit), and cast-out operators (explicit).
The variable names in the cast-out operators changed to "real" for the very simple reason that this is what JetBrains Rider's "guess a new variable name here" template expander wanted and just going with that is much less effort than going back and shorting it to "r" when I'm writing this much boilerplate.
@the-og-gear or @Lathreas , please merge unless you have more comments.
Real is a type that, in debug mode, acts like a float, and in release mode, acts like a double. A compiler flag can be provided to override this behavior.
I didn't reimplement the Math library, so you'll have to do some casts to and from double if you want to use it. If that gets annoying, implement convenience methods at your discretion.
It builds, but it hasn't been tested yet. My next major project is to get a unit test engine up and going and start writing unit tests in this codebase, probably starting right here.
Extra features compared to
double
: operator ! is implemented, converting zero (and negative zero) to 1.0, nonzero non-NaN values to 0.0, and NaN remains NaN, which seems like the most appropriate interpretation of unary "!" in floating-point. Many things that are static methods on Double are instance properties on Real. I've added IsNear, IsAbsolutelyNear, and IsRelativelyNear to implement "close enough equality". (With all the warnings about "aaaagh! never compare floating-point values for exact equality! aaaaarrrgh!" that languages and compilers give us, you'd think the language libraries would build this in. Well, I'm writing this one, so I did.Please review.