I need to use an unsigned double but it turns out C# does not provide such a type.
Does anyone know why?
It is highly curable ... Direct-acting antiviral medications — given over a 12-week period — actually can cure early acute hepatitis C better than 90% of the time.
Logical OR operator: || The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise. The operands are implicitly converted to type bool before evaluation, and the result is of type bool .
The hepatitis C (HCV) window period is usually 4–10 weeks from the time of exposure. After 6 months , most people will have developed enough antibodies for an HCV test to detect. In rare cases, however, antibodies can take up to 9 months to develop.
As pointed out by Anders Forsgren, there is no unsigned doubles in the IEEE spec (and therefore not in C#).
You can always get the positive value by calling Math.Abs() and you could wrap a double in a struct and enforce the constraint there:
public struct PositiveDouble { private double _value; public PositiveDouble() {} public PositiveDouble(double val) { // or truncate/take Abs value automatically? if (val < 0) throw new ArgumentException("Value needs to be positive"); _value = val; } // This conversion is safe, we can make it implicit public static implicit operator double(PositiveDouble d) { return d._value; } // This conversion is not always safe, so we make it explicit public static explicit operator PositiveDouble(double d) { // or truncate/take Abs value automatically? if (d < 0) throw new ArgumentOutOfRangeException("Only positive values allowed"); return new PositiveDouble(d); } // add more cast operators if needed }
Floating point numbers are simply the implementation of the IEEE 754 spec. There is no such thing as an unsigned double there as far as i know.
http://en.wikipedia.org/wiki/IEEE_754-2008
Why do you need an unsigned floating point number?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With