PeterO.Cbor.CBORNumber

## PeterO.Cbor.CBORNumber

public sealed class CBORNumber :
    System.IComparable

An instance of a number that CBOR or certain CBOR tags can represent. For this purpose, infinities and not-a-number or NaN values are considered numbers. Currently, this class can store one of the following kinds of numbers: 64-bit signed integers or binary floating-point numbers; or arbitrary-precision integers, decimal numbers, binary numbers, or rational numbers.

Member Summary

### Kind

public PeterO.Cbor.CBORNumber.NumberKind Kind { get; }

Gets the underlying form of this CBOR number object.

Returns:

The underlying form of this CBOR number object.

### Sign

public int Sign { get; }

Gets this value’s sign: -1 if nonzero and negative; 1 if nonzero and positive; 0 if zero. Not-a-number (NaN) values are positive or negative depending on what sign is stored in their underlying forms.

Returns:

This value’s sign.

### Abs

public PeterO.Cbor.CBORNumber Abs();

Returns the absolute value of this CBOR number.

Return Value:

This object’s absolute value without its negative sign.

### Add

public PeterO.Cbor.CBORNumber Add(
    PeterO.Cbor.CBORNumber b);

Returns the sum of this number and another number.

Parameters:

Return Value:

The sum of this number and another number.

Exceptions:

### CanFitInDouble

public bool CanFitInDouble();

Returns whether this object’s value can be converted to a 64-bit floating point number without its value being rounded to another numerical value.

Return Value:

true if this object’s value can be converted to a 64-bit floating point number without its value being rounded to another numerical value, or if this is a not-a-number value, even if the value’s diagnostic information can’t fit in a 64-bit floating point number; otherwise, false .

### CanFitInInt32

public bool CanFitInInt32();

Returns whether this object’s numerical value is an integer, is -(2^31) or greater, and is less than 2^31.

Return Value:

true if this object’s numerical value is an integer, is -(2^31) or greater, and is less than 2^31; otherwise, false .

### CanFitInInt64

public bool CanFitInInt64();

Returns whether this object’s numerical value is an integer, is -(2^63) or greater, and is less than 2^63.

Return Value:

true if this object’s numerical value is an integer, is -(2^63) or greater, and is less than 2^63; otherwise, false .

### CanFitInSingle

public bool CanFitInSingle();

Returns whether this object’s value can be converted to a 32-bit floating point number without its value being rounded to another numerical value.

Return Value:

true if this object’s value can be converted to a 32-bit floating point number without its value being rounded to another numerical value, or if this is a not-a-number value, even if the value’s diagnostic information can’ t fit in a 32-bit floating point number; otherwise, false .

### CanFitInUInt64

public bool CanFitInUInt64();

Returns whether this object’s numerical value is an integer, is 0 or greater, and is less than 2^64.

Return Value:

true if this object’s numerical value is an integer, is 0 or greater, and is less than 2^64; otherwise, false .

### CanTruncatedIntFitInInt32

public bool CanTruncatedIntFitInInt32();

Returns whether this object’s value, converted to an integer by discarding its fractional part, would be -(2^31) or greater, and less than 2^31.

Return Value:

true if this object’s value, converted to an integer by discarding its fractional part, would be -(2^31) or greater, and less than 2^31; otherwise, false .

### CanTruncatedIntFitInInt64

public bool CanTruncatedIntFitInInt64();

Returns whether this object’s value, converted to an integer by discarding its fractional part, would be -(2^63) or greater, and less than 2^63.

Return Value:

true if this object’s value, converted to an integer by discarding its fractional part, would be -(2^63) or greater, and less than 2^63; otherwise, false .

### CanTruncatedIntFitInUInt64

public bool CanTruncatedIntFitInUInt64();

Returns whether this object’s value, converted to an integer by discarding its fractional part, would be 0 or greater, and less than 2^64.

Return Value:

true if this object’s value, converted to an integer by discarding its fractional part, would be 0 or greater, and less than 2^64; otherwise, false .

### CompareTo

public int CompareTo(
    int other);

Compares this CBOR number with a 32-bit signed integer. In this implementation, the two numbers’ mathematical values are compared. Here, NaN (not-a-number) is considered greater than any number.

Parameters:

Return Value:

A negative number, if this value is less than the other object; or 0, if both values are equal; or a positive number, if this value is less than the other object or if the other object is null. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareTo

public int CompareTo(
    long other);

Compares this CBOR number with a 64-bit signed integer. In this implementation, the two numbers’ mathematical values are compared. Here, NaN (not-a-number) is considered greater than any number.

Parameters:

Return Value:

A negative number, if this value is less than the other object; or 0, if both values are equal; or a positive number, if this value is less than the other object or if the other object is null. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### CompareTo

public sealed int CompareTo(
    PeterO.Cbor.CBORNumber other);

Compares this CBOR number with another. In this implementation, the two numbers’ mathematical values are compared. Here, NaN (not-a-number) is considered greater than any number.

Parameters:

Return Value:

A negative number, if this value is less than the other object; or 0, if both values are equal; or a positive number, if this value is less than the other object or if the other object is null. This implementation returns a positive number if other is null, to conform to the.NET definition of CompareTo. This is the case even in the Java version of this library, for consistency’s sake, even though implementations of Comparable.compareTo() in Java ought to throw an exception if they receive a null argument rather than treating null as less or greater than any object.

.

### Divide

public PeterO.Cbor.CBORNumber Divide(
    PeterO.Cbor.CBORNumber b);

Returns the quotient of this number and another number.

Parameters:

Return Value:

The quotient of this number and another one.

Exceptions:

### FromByte

public static PeterO.Cbor.CBORNumber FromByte(
    byte inputByte);

Converts a byte (from 0 to 255) to an arbitrary-precision decimal number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision decimal number.

### FromCBORObject

public static PeterO.Cbor.CBORNumber FromCBORObject(
    PeterO.Cbor.CBORObject o);

Creates a CBOR number object from a CBOR object representing a number (that is, one for which the IsNumber property in.NET or the isNumber() method in Java returns true).

Parameters:

Return Value:

A CBOR number object, or null if the given CBOR object is null or does not represent a number.

### FromInt16

public static PeterO.Cbor.CBORNumber FromInt16(
    short inputInt16);

Converts a 16-bit signed integer to an arbitrary-precision decimal number.

Parameters:

Return Value:

This number’s value as an arbitrary-precision decimal number.

### IsFinite

public bool IsFinite();

Gets a value indicating whether this CBOR object represents a finite number.

Return Value:

true if this CBOR object represents a finite number; otherwise, false .

### IsInfinity

public bool IsInfinity();

Gets a value indicating whether this object represents infinity.

Return Value:

true if this object represents infinity; otherwise, false .

### IsInteger

public bool IsInteger();

Gets a value indicating whether this object represents an integer number, that is, a number without a fractional part. Infinity and not-a-number are not considered integers.

Return Value:

true if this object represents an integer number, that is, a number without a fractional part; otherwise, false .

### IsNaN

public bool IsNaN();

Gets a value indicating whether this object represents a not-a-number value.

Return Value:

true if this object represents a not-a-number value; otherwise, false .

### IsNegative

public bool IsNegative();

Gets a value indicating whether this object is a negative number.

Return Value:

true if this object is a negative number; otherwise, false .

### IsNegativeInfinity

public bool IsNegativeInfinity();

Gets a value indicating whether this object represents negative infinity.

Return Value:

true if this object represents negative infinity; otherwise, false .

### IsPositiveInfinity

public bool IsPositiveInfinity();

Gets a value indicating whether this object represents positive infinity.

Return Value:

true if this object represents positive infinity; otherwise, false .

### IsZero

public bool IsZero();

Gets a value indicating whether this object’s value equals 0.

Return Value:

true if this object’s value equals 0; otherwise, false .

### Multiply

public PeterO.Cbor.CBORNumber Multiply(
    PeterO.Cbor.CBORNumber b);

Returns a CBOR number expressing the product of this number and the given number.

Parameters:

Return Value:

A number expressing the product of this number and the given number.

Exceptions:

### Negate

public PeterO.Cbor.CBORNumber Negate();

Returns a CBOR number with the same value as this one but with the sign reversed.

Return Value:

A CBOR number with the same value as this one but with the sign reversed.

### Operator >

public static bool operator >(
    PeterO.Cbor.CBORNumber a,
    PeterO.Cbor.CBORNumber b);

Returns whether one object’s value is greater than another’s.

Parameters:

Return Value:

true if one object’s value is greater than another’s; otherwise, false .

Exceptions:

### Operator >=

public static bool operator >=(
    PeterO.Cbor.CBORNumber a,
    PeterO.Cbor.CBORNumber b);

Returns whether one object’s value is at least another’s.

Parameters:

Return Value:

true if one object’s value is at least another’s; otherwise, false .

Exceptions:

### Operator <

public static bool operator <(
    PeterO.Cbor.CBORNumber a,
    PeterO.Cbor.CBORNumber b);

Returns whether one object’s value is less than another’s.

Parameters:

Return Value:

true if the first object’s value is less than the other’s; otherwise, false .

Exceptions:

### Operator <=

public static bool operator <=(
    PeterO.Cbor.CBORNumber a,
    PeterO.Cbor.CBORNumber b);

Returns whether one object’s value is up to another’s.

Parameters:

Return Value:

true if one object’s value is up to another’s; otherwise, false .

Exceptions:

### Remainder

public PeterO.Cbor.CBORNumber Remainder(
    PeterO.Cbor.CBORNumber b);

Returns the remainder when this number is divided by another number.

Parameters:

Return Value:

The remainder when this number is divided by the other number.

Exceptions:

### Subtract

public PeterO.Cbor.CBORNumber Subtract(
    PeterO.Cbor.CBORNumber b);

Returns a number that expresses this number minus another.

Parameters:

Return Value:

A CBOR number that expresses this number minus the given number.

Exceptions:

### ToByteChecked

public byte ToByteChecked();

Converts this number’s value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a byte (from 0 to 255).

Exceptions:

### ToByteIfExact

public byte ToByteIfExact();

Converts this number’s value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) without rounding to a different numerical value.

Return Value:

This number’s value as a byte (from 0 to 255).

Exceptions:

### ToByteUnchecked

public byte ToByteUnchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a byte (from 0 to 255).

Return Value:

This number, converted to a byte (from 0 to 255). Returns 0 if this value is infinity or not-a-number.

### ToCBORObject

public PeterO.Cbor.CBORObject ToCBORObject();

Converts this object’s value to a CBOR object.

Return Value:

A CBOR object that stores this object’s value.

### ToEDecimal

public PeterO.Numbers.EDecimal ToEDecimal();

Converts this object to a decimal number.

Return Value:

A decimal number for this object’s value.

### ToEFloat

public PeterO.Numbers.EFloat ToEFloat();

Converts this object to an arbitrary-precision binary floating point number. See the ToObject overload taking a type for more information.

Return Value:

An arbitrary-precision binary floating-point number for this object’s value.

### ToEInteger

public PeterO.Numbers.EInteger ToEInteger();

Converts this object to an arbitrary-precision integer. See the ToObject overload taking a type for more information.

Return Value:

The closest arbitrary-precision integer to this object.

Exceptions:

### ToEIntegerIfExact

public PeterO.Numbers.EInteger ToEIntegerIfExact();

Converts this object to an arbitrary-precision integer if its value is an integer.

Return Value:

The arbitrary-precision integer given by object.

Exceptions:

### ToERational

public PeterO.Numbers.ERational ToERational();

Converts this object to a rational number. See the ToObject overload taking a type for more information.

Return Value:

A rational number for this object’s value.

### ToInt16Checked

public short ToInt16Checked();

Converts this number’s value to a 16-bit signed integer if it can fit in a 16-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 16-bit signed integer.

Exceptions:

### ToInt16IfExact

public short ToInt16IfExact();

Converts this number’s value to a 16-bit signed integer if it can fit in a 16-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 16-bit signed integer.

Exceptions:

### ToInt16Unchecked

public short ToInt16Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 16-bit signed integer.

Return Value:

This number, converted to a 16-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToInt32Checked

public int ToInt32Checked();

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 32-bit signed integer.

Exceptions:

### ToInt32IfExact

public int ToInt32IfExact();

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 32-bit signed integer.

Exceptions:

### ToInt32Unchecked

public int ToInt32Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 32-bit signed integer.

Return Value:

This number, converted to a 32-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToInt64Checked

public long ToInt64Checked();

Converts this number’s value to a 64-bit signed integer if it can fit in a 64-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 64-bit signed integer.

Exceptions:

### ToInt64IfExact

public long ToInt64IfExact();

Converts this number’s value to a 64-bit signed integer if it can fit in a 64-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 64-bit signed integer.

Exceptions:

### ToInt64Unchecked

public long ToInt64Unchecked();

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 64-bit signed integer.

Return Value:

This number, converted to a 64-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToSByteChecked

public sbyte ToSByteChecked();

This API is not CLS-compliant.

Converts this number’s value to an 8-bit signed integer if it can fit in an 8-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to an 8-bit signed integer.

Exceptions:

### ToSByteIfExact

public sbyte ToSByteIfExact();

This API is not CLS-compliant.

Converts this number’s value to an 8-bit signed integer if it can fit in an 8-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as an 8-bit signed integer.

Exceptions:

### ToSByteUnchecked

public sbyte ToSByteUnchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as an 8-bit signed integer.

Return Value:

This number, converted to an 8-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToString

public override string ToString();

Returns the value of this object in text form.

Return Value:

A text string representing the value of this object.

### ToUInt16Checked

public ushort ToUInt16Checked();

This API is not CLS-compliant.

Converts this number’s value to a 16-bit unsigned integer if it can fit in a 16-bit unsigned integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 16-bit unsigned integer.

Exceptions:

### ToUInt16IfExact

public ushort ToUInt16IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 16-bit unsigned integer if it can fit in a 16-bit unsigned integer without rounding to a different numerical value.

Return Value:

This number’s value as a 16-bit unsigned integer.

Exceptions:

### ToUInt16Unchecked

public ushort ToUInt16Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 16-bit unsigned integer.

Return Value:

This number, converted to a 16-bit unsigned integer. Returns 0 if this value is infinity or not-a-number.

### ToUInt32Checked

public uint ToUInt32Checked();

This API is not CLS-compliant.

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 32-bit signed integer.

Exceptions:

### ToUInt32IfExact

public uint ToUInt32IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 32-bit signed integer if it can fit in a 32-bit signed integer without rounding to a different numerical value.

Return Value:

This number’s value as a 32-bit signed integer.

Exceptions:

### ToUInt32Unchecked

public uint ToUInt32Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 32-bit signed integer.

Return Value:

This number, converted to a 32-bit signed integer. Returns 0 if this value is infinity or not-a-number.

### ToUInt64Checked

public ulong ToUInt64Checked();

This API is not CLS-compliant.

Converts this number’s value to a 64-bit unsigned integer if it can fit in a 64-bit unsigned integer after converting it to an integer by discarding its fractional part.

Return Value:

This number’s value, truncated to a 64-bit unsigned integer.

Exceptions:

### ToUInt64IfExact

public ulong ToUInt64IfExact();

This API is not CLS-compliant.

Converts this number’s value to a 64-bit unsigned integer if it can fit in a 64-bit unsigned integer without rounding to a different numerical value.

Return Value:

This number’s value as a 64-bit unsigned integer.

Exceptions:

### ToUInt64Unchecked

public ulong ToUInt64Unchecked();

This API is not CLS-compliant.

Converts this number’s value to an integer by discarding its fractional part, and returns the least-significant bits of its two’s-complement form as a 64-bit unsigned integer.

Return Value:

This number, converted to a 64-bit unsigned integer. Returns 0 if this value is infinity or not-a-number.

Back to CBOR start page.