IntToU64
Description
Convert an integer to u64.
This public macro supports both forms:
IntToU64(value)- returns the result, no error channel.IntToU64(value, error)- writes the error flag througherror.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to convert. |
error |
out | Optional pointer set to true on failure and false on success. |
Usage example (from documentation)
u64 v = IntToU64(&big);Success
Returns the numeric value as a u64. The integer is not modified.
Failure
Returns 0 when the value does not fit in 64 bits. With the two-argument form *error is set to true; with the one-argument form the caller cannot distinguish overflow from a true zero result.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:1289:
}
return int_pow_u64(result, base, IntToU64(exponent));
}- In
Int.c:1581:
return 0;
}
rem = IntToU64(&remainder);
IntDeinit(&divisor_value);- In
Int.Convert.c:48:
bool result = IntBitLength(&value) == 4;
result = result && (IntToU64(&value) == 13);
result = result && (ZstrCompare(StrBegin(&text), "1101") == 0); Str text = IntToBinary(&value);
bool result = IntToU64(&value) == 11;
result = result && (ZstrCompare(StrBegin(&text), "1011") == 0); Str text = IntToStrRadix(&value, 36, false);
bool result = IntToU64(&value) == 1295;
result = result && (ZstrCompare(StrBegin(&text), "zz") == 0); bool result = IntBitLength(&zero) == 0;
result = result && IntIsZero(&zero);
result = result && (IntToU64(&zero, &error) == 0);
result = result && !error;
result = result && (ZstrCompare(StrBegin(&text), "0") == 0); Int value = IntFromBinary("0b1010_0011", ALLOCATOR_OF(&alloc));
bool result = IntToU64(&value) == 163;
result = result && (IntBitLength(&value) == 8); Str text = IntToOctStr(&value);
bool result = IntToU64(&value) == 493;
result = result && (ZstrCompare(StrBegin(&text), "755") == 0);
bool test_int_to_u64_overflow(void) {
WriteFmt("Testing IntToU64 overflow handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();
bool result = !IntTryToU64(&value, &out);
result = result && (IntToU64(&value, &error) == 0);
result = result && error;
result = result && (out == 0);- In
Int.Type.c:55:
bool result = IntEQ(&clone, &original);
result = result && (IntToU64(&clone) == 11);
IntShiftLeft(&original, 1);- In
Int.Type.c:60:
result = result && !IntEQ(&clone, &original);
result = result && (IntToU64(&clone) == 11);
result = result && (IntToU64(&original) == 22);- In
Int.Type.c:61:
result = result && !IntEQ(&clone, &original);
result = result && (IntToU64(&clone) == 11);
result = result && (IntToU64(&original) == 22);
IntDeinit(&original);- In
Int.Math.c:71:
IntShiftLeft(&value, 4);
bool result = IntToU64(&value) == 48;
result = result && (IntBitLength(&value) == 6);- In
Int.Math.c:88:
IntShiftRight(&value, 4);
bool result = IntToU64(&value) == 3;
result = result && (IntBitLength(&value) == 2);- In
Int.Math.c:109:
text = IntToBinary(&result_value);
bool result = IntToU64(&result_value) == 256;
result = result && (ZstrCompare(StrBegin(&text), "100000000") == 0);- In
Int.Math.c:132:
IntAdd(&result_value, &base, &rhs);
bool result = IntToU64(&result_value) == 42;
IntAdd(&result_value, &base, 2);- In
Int.Math.c:135:
IntAdd(&result_value, &base, 2);
result = result && (IntToU64(&result_value) == 42);
IntAdd(&result_value, &base, -2);- In
Int.Math.c:138:
IntAdd(&result_value, &base, -2);
result = result && (IntToU64(&result_value) == 38);
IntAdd(&result_value, &huge, 10);- In
Int.Math.c:163:
bool result = IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 255);
IntDeinit(&a);- In
Int.Math.c:185:
bool result = IntSub(&result_value, &base, &rhs);
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, 2u);- In
Int.Math.c:188:
result = result && IntSub(&result_value, &base, 2u);
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, -2);- In
Int.Math.c:191:
result = result && IntSub(&result_value, &base, -2);
result = result && (IntToU64(&result_value) == 42);
result = result && IntSub(&result_value, &huge, 90);- In
Int.Math.c:198:
result = result && !IntSub(&preserved, &base, 50);
result = result && (IntToU64(&preserved) == 99);
IntDeinit(&base);- In
Int.Math.c:220:
bool result = !IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 99);
IntDeinit(&a);- In
Int.Math.c:240:
IntMul(&result_value, &a, &b);
bool result = IntToU64(&result_value) == 126;
IntDeinit(&a);- In
Int.Math.c:282:
bool result = IntIsZero(&result_value);
result = result && (IntToU64(&result_value) == 0);
IntDeinit(&a);- In
Int.Math.c:301:
IntSquare(&result_value, &value);
bool result = IntToU64(&result_value) == 152399025;
IntDeinit(&value);- In
Int.Math.c:350:
bool result = ZstrCompare(StrBegin(&qtext), "127275040218913071") == 0;
result = result && (IntToU64(&remainder) == 3);
StrDeinit(&qtext);- In
Int.Math.c:370:
IntDiv(&result_value, ÷nd, 10u);
bool result = IntToU64(&result_value) == 12;
IntDeinit(÷nd);- In
Int.Math.c:408:
bool result = !IntDivExact(&result_value, ÷nd, &divisor);
result = result && (IntToU64(&result_value) == 99);
IntDeinit(÷nd);- In
Int.Math.c:431:
bool result = ZstrCompare(StrBegin(&text), "127275040218913071") == 0;
result = result && (IntToU64(&remainder) == 3);
IntDeinit(÷nd);- In
Int.Math.c:451:
IntMod(&result_value, ÷nd, 10u);
bool result = IntToU64(&result_value) == 6;
IntDeinit(÷nd);- In
Int.Math.c:470:
IntDeinit(&value);
bool result = IntToU64(&remainder) == 3;
IntDeinit(&remainder);
DefaultAllocatorDeinit(&alloc);- In
Int.Math.c:487:
IntGCD(&result_value, &a, &b);
bool result = IntToU64(&result_value) == 6;
IntDeinit(&a);- In
Int.Math.c:507:
IntLCM(&result_value, &a, &b);
bool result = IntToU64(&result_value) == 42;
IntDeinit(&a);- In
Int.Math.c:526:
IntRoot(&result_value, &value, 4);
bool result = IntToU64(&result_value) == 8;
IntDeinit(&value);- In
Int.Math.c:545:
IntRootRem(&root, &remainder, &value, 3);
bool result = IntToU64(&root) == 5;
result = result && (IntToU64(&remainder) == 75);- In
Int.Math.c:546:
bool result = IntToU64(&root) == 5;
result = result && (IntToU64(&remainder) == 75);
IntDeinit(&value);- In
Int.Math.c:565:
IntSqrt(&result_value, &value);
bool result = IntToU64(&result_value) == 14;
IntDeinit(&value);- In
Int.Math.c:584:
IntSqrtRem(&root, &remainder, &value);
bool result = IntToU64(&root) == 14;
result = result && (IntToU64(&remainder) == 4);- In
Int.Math.c:585:
bool result = IntToU64(&root) == 14;
result = result && (IntToU64(&remainder) == 4);
IntDeinit(&value);- In
Int.Math.c:663:
IntSquareMod(&result_value, &value, &mod);
bool result = IntToU64(&result_value) == 94;
IntDeinit(&value);- In
Int.Math.c:684:
IntModAdd(&result_value, &a, &b, &m);
bool result = IntToU64(&result_value) == 12;
IntDeinit(&a);- In
Int.Math.c:706:
IntModSub(&result_value, &a, &b, &m);
bool result = IntToU64(&result_value) == 9;
IntDeinit(&a);- In
Int.Math.c:728:
IntModMul(&result_value, &a, &b, &m);
bool result = IntToU64(&result_value) == 22;
IntDeinit(&a);- In
Int.Math.c:750:
bool result = IntModDiv(&result_value, &a, &b, &m);
result = result && (IntToU64(&result_value) == 12);
IntModMul(&check, &result_value, &b, &m);- In
Int.Math.c:775:
IntPowMod(&result_value, &base, 20u, &mod);
bool result = IntToU64(&result_value) == 3;
IntDeinit(&base);- In
Int.Math.c:796:
IntPowMod(&result_value, &base, &exp, &mod);
bool result = IntToU64(&result_value) == 445;
IntDeinit(&base);- In
Int.Math.c:817:
bool result = IntModInv(&result_value, &value, &mod);
result = result && (IntToU64(&result_value) == 4);
IntModMul(&check, &value, &result_value, &mod);- In
Int.Math.c:820:
IntModMul(&check, &value, &result_value, &mod);
result = result && (IntToU64(&check) == 1);
IntDeinit(&value);- In
Int.Math.c:919:
bool result = !IntModInv(&result_value, &value, &mod);
result = result && (IntToU64(&result_value) == 99);
IntDeinit(&value);
Last updated on