-// CONVERSION TO PRIMITIVE INTEGERS
-
-/* Template with the same idea as initFromPrimitive. This might be slightly
- * slower than the previous version with the masks, but it's much shorter and
- * clearer, which is the library's stated goal. */
-template <class X>
-X BigUnsigned::convertToPrimitive() const {
- if (len == 0)
- // The number is zero; return zero.
- return 0;
- else if (len == 1) {
- // The single block might fit in an X. Try the conversion.
- X x = X(blk[0]);
- // Make sure the result accurately represents the block.
- if (Blk(x) == blk[0])
- // Successful conversion.
- return x;
- // Otherwise fall through.
- }
- throw "BigUnsigned::to<Primitive>: "
- "Value is too big to fit in the requested type";
-}
-
-/* Wrap the above in an x >= 0 test to make sure we got a nonnegative result,
- * not a negative one that happened to convert back into the correct nonnegative
- * one. (E.g., catch incorrect conversion of 2^31 to the long -2^31.) Again,
- * separated to avoid a g++ warning. */
-template <class X>
-X BigUnsigned::convertToSignedPrimitive() const {
- X x = convertToPrimitive<X>();
- if (x >= 0)
- return x;
- else
- throw "BigUnsigned::to(Primitive): "
- "Value is too big to fit in the requested type";
-}
-
-unsigned long BigUnsigned::toUnsignedLong() const {
- return convertToPrimitive<unsigned long>();
-}
-unsigned int BigUnsigned::toUnsignedInt() const {
- return convertToPrimitive<unsigned int>();
-}
-unsigned short BigUnsigned::toUnsignedShort() const {
- return convertToPrimitive<unsigned short>();
-}
-long BigUnsigned::toLong() const {
- return convertToSignedPrimitive<long>();
-}
-int BigUnsigned::toInt() const {
- return convertToSignedPrimitive<int>();
-}
-short BigUnsigned::toShort() const {
- return convertToSignedPrimitive<short>();
-}
+unsigned long BigUnsigned::toUnsignedLong () const { return convertToPrimitive <unsigned long >(); }
+unsigned int BigUnsigned::toUnsignedInt () const { return convertToPrimitive <unsigned int >(); }
+unsigned short BigUnsigned::toUnsignedShort() const { return convertToPrimitive <unsigned short>(); }
+long BigUnsigned::toLong () const { return convertToSignedPrimitive< long >(); }
+int BigUnsigned::toInt () const { return convertToSignedPrimitive< int >(); }
+short BigUnsigned::toShort () const { return convertToSignedPrimitive< short>(); }