/** * Initialize algorithm context before calculaing hash. * * @param ctx context to initialize */ void rhash_tiger_init(tiger_ctx *ctx) { ctx->length = 0; ctx->tiger2 = 0; /* initialize algorithm state */ ctx->hash[0] = I64(0x0123456789ABCDEF); ctx->hash[1] = I64(0xFEDCBA9876543210); ctx->hash[2] = I64(0xF096A5B4C3B2E187); }
int __cdecl main(int argc, char *argv[]) { int neg = -42; int pos = 0x1234AB; INT64 l = I64(0x1234567887654321); if (PAL_Initialize(argc, argv) != 0) { return FAIL; } DoNumTest("foo %X", pos, "foo 1234AB"); DoNumTest("foo %lX", pos, "foo 1234AB"); DoNumTest("foo %hX", pos, "foo 34AB"); DoNumTest("foo %LX", pos, "foo 1234AB"); DoI64Test("foo %I64X", l, "0x1234567887654321", "foo 1234567887654321"); DoNumTest("foo %7X", pos, "foo 1234AB"); DoNumTest("foo %-7X", pos, "foo 1234AB "); DoNumTest("foo %.1X", pos, "foo 1234AB"); DoNumTest("foo %.7X", pos, "foo 01234AB"); DoNumTest("foo %07X", pos, "foo 01234AB"); DoNumTest("foo %#X", pos, "foo 0X1234AB"); DoNumTest("foo %+X", pos, "foo 1234AB"); DoNumTest("foo % X", pos, "foo 1234AB"); DoNumTest("foo %+X", neg, "foo FFFFFFD6"); DoNumTest("foo % X", neg, "foo FFFFFFD6"); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { int n65535 = 65535; /* Walkaround compiler strictness */ if (PAL_Initialize(argc, argv)) { return FAIL; } DoNumTest(convert("1234d"), convert("%d"), 1234); DoNumTest(convert("1234d"), convert("%2d"), 12); DoNumTest(convert("-1"), convert("%d"), -1); DoNumTest(convert("0x1234"), convert("%d"), 0); DoNumTest(convert("012"), convert("%d"), 12); DoShortNumTest(convert("-1"), convert("%hd"), n65535); DoShortNumTest(convert("65536"), convert("%hd"), 0); DoNumTest(convert("-1"), convert("%ld"), -1); DoNumTest(convert("65536"), convert("%ld"), 65536); DoNumTest(convert("-1"), convert("%Ld"), -1); DoNumTest(convert("65536"), convert("%Ld"), 65536); DoI64NumTest(convert("4294967296"), convert("%I64d"), I64(4294967296)); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { void *ptr = (void*) 0x123456; INT64 lptr = I64(0x1234567887654321); if (PAL_Initialize(argc, argv) != 0) return(FAIL); DoPointerTest("%p", NULL, "NULL", "00000000"); DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456"); DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456"); DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456"); DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 "); DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456"); DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456"); DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456"); DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456"); DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456"); DoI64DoubleTest("%I64p", lptr, "pointer to 0x1234567887654321", "1234567887654321"); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { int neg = -42; int pos = 0x1234ab; INT64 l = I64(0x1234567887654321); if (PAL_Initialize(argc, argv)) { return FAIL; } DoNumTest("foo %x", pos, "foo 1234ab"); DoNumTest("foo %lx", pos, "foo 1234ab"); DoNumTest("foo %hx", pos, "foo 34ab"); DoNumTest("foo %Lx", pos, "foo 1234ab"); DoI64Test("foo %I64x", l, "0x1234567887654321", "foo 1234567887654321"); DoNumTest("foo %7x", pos, "foo 1234ab"); DoNumTest("foo %-7x", pos, "foo 1234ab "); DoNumTest("foo %.1x", pos, "foo 1234ab"); DoNumTest("foo %.7x", pos, "foo 01234ab"); DoNumTest("foo %07x", pos, "foo 01234ab"); DoNumTest("foo %#x", pos, "foo 0x1234ab"); DoNumTest("foo %+x", pos, "foo 1234ab"); DoNumTest("foo % x", pos, "foo 1234ab"); DoNumTest("foo %+x", neg, "foo ffffffd6"); DoNumTest("foo % x", neg, "foo ffffffd6"); PAL_Terminate(); return PASS; }
/** * Calculate default torrent piece length, using uTorrent algorithm. * Algorithm: * length = 16K for total_size < 16M, * length = 8M for total_size >= 4G, * length = top_bit(total_size) / 1024 otherwise. * * @param total_size total hashed batch size of torrent file * @return piece length used by torrent file */ size_t bt_default_piece_length(uint64_t total_size) { uint64_t hi_bit; if(total_size < 16777216) return BT_MIN_HASH_LENGTH; if(total_size >= I64(4294967296) ) return 8388608; for(hi_bit = 16777216 << 1; hi_bit <= total_size; hi_bit <<= 1); return (size_t)(hi_bit >> 10); }
/** * Calculate default torrent piece length, using uTorrent algorithm. * Algorithm: * length = 64K for total_size < 64M, * length = 4M for total_size >= 2G, * length = top_bit(total_size) / 512 otherwise. * * @param total_size total hashed batch size of torrent file * @return piece length used by torrent file */ size_t torrent_default_piece_length(uint64_t total_size) { uint64_t hi_bit; if(total_size < 67108864) return 65536; if(total_size >= I64(2147483648) ) return 4194304; for(hi_bit = 67108864 << 1; hi_bit <= total_size; hi_bit <<= 1); return (size_t)(hi_bit >> 10); }
static void cfunction2(asINT64 i1, float f2, char i3, int i4) { called = true; g1 = i1; g2 = f2; g3 = i3; g4 = i4; testVal = ((i1 == I64(0x102030405)) && (f2 == 3) && (i3 == 24) && (i4 == 128)); }
static void get_system_time(uuid_time_t *uuid_time) { struct timeval tp; gettimeofday(&tp, (struct timezone *)0); /* Offset between UUID formatted times and Unix formatted times. UUID UTC base time is October 15, 1582. Unix base time is January 1, 1970. */ *uuid_time = (tp.tv_sec * 10000000) + (tp.tv_usec * 10) + I64(0x01B21DD213814000); }
static void internalize_phdr(Elf_Byte bo, Elf_Phdr *phdr) { #if ELFSIZE == 32 I32(phdr->p_type); I32(phdr->p_offset); I32(phdr->p_vaddr); I32(phdr->p_paddr); I32(phdr->p_filesz); I32(phdr->p_memsz); I32(phdr->p_flags); I32(phdr->p_align); #elif ELFSIZE == 64 I32(phdr->p_type); I32(phdr->p_offset); I64(phdr->p_vaddr); I64(phdr->p_paddr); I64(phdr->p_filesz); I64(phdr->p_memsz); I64(phdr->p_flags); I64(phdr->p_align); #else #error ELFSIZE is not 32 or 64 #endif }
static void internalize_shdr(Elf_Byte bo, Elf_Shdr *shdr) { #if ELFSIZE == 32 I32(shdr->sh_name); I32(shdr->sh_type); I32(shdr->sh_flags); I32(shdr->sh_addr); I32(shdr->sh_offset); I32(shdr->sh_size); I32(shdr->sh_link); I32(shdr->sh_info); I32(shdr->sh_addralign); I32(shdr->sh_entsize); #elif ELFSIZE == 64 I32(shdr->sh_name); I32(shdr->sh_type); I64(shdr->sh_flags); I64(shdr->sh_addr); I64(shdr->sh_offset); I64(shdr->sh_size); I32(shdr->sh_link); I32(shdr->sh_info); I64(shdr->sh_addralign); I64(shdr->sh_entsize); #else #error ELFSIZE is not 32 or 64 #endif }
template<> void Jsonize(JsonIO& io, int64& var) { if(io.IsLoading()) { const Value& v = io.Get(); if(IsNull(v)) { var = Null; return; } if(v.Is<int64>() || v.Is<int>()) { var = v; return; } if(IsNumber(v)) { double d = v; if(d >= INT64_MIN && d <= INT64_MAX) { var = (int64)d; return; } } else if(IsString(v)) { int64 h = ScanInt64((String)v); if(!IsNull(h)) { var = h; return; } } throw JsonizeError("invalid int64 value"); } else if(IsNull(var)) io.Set(Null); else if(var >= I64(-9007199254740992) && var <= I64(9007199254740991)) io.Set(var); else io.Set(AsString(var)); }
static void internalize_ehdr(Elf_Byte bo, Elf_Ehdr *ehdr) { #if ELFSIZE == 32 I16(ehdr->e_type); I16(ehdr->e_machine); I32(ehdr->e_version); I32(ehdr->e_entry); I32(ehdr->e_phoff); I32(ehdr->e_shoff); I32(ehdr->e_flags); I16(ehdr->e_ehsize); I16(ehdr->e_phentsize); I16(ehdr->e_phnum); I16(ehdr->e_shentsize); I16(ehdr->e_shnum); I16(ehdr->e_shstrndx); #elif ELFSIZE == 64 I16(ehdr->e_type); I16(ehdr->e_machine); I32(ehdr->e_version); I64(ehdr->e_entry); I64(ehdr->e_phoff); I64(ehdr->e_shoff); I32(ehdr->e_flags); I16(ehdr->e_ehsize); I16(ehdr->e_phentsize); I16(ehdr->e_phnum); I16(ehdr->e_shentsize); I16(ehdr->e_shnum); I16(ehdr->e_shstrndx); #else #error ELFSIZE is not 32 or 64 #endif }
int __cdecl main(int argc, char *argv[]) { void *ptr = (void*) 0x123456; INT64 lptr = I64(0x1234567887654321); if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /* ** Run only on 64 bit platforms */ #if defined(BIT64) && defined(PLATFORM_UNIX) Trace("Testing for 64 Bit Platforms \n"); DoPointerTest(convert("%p"), NULL, convert("0000000000000000")); DoPointerTest(convert("%p"), ptr, convert("0000000000123456")); DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); DoPointerTest(convert("%17p"), ptr, convert(" 0000000000123456")); DoPointerTest(convert("%-17p"), ptr, convert("0000000000123456 ")); DoPointerTest(convert("%+p"), ptr, convert("0000000000123456")); DoPointerTest(convert("% p"), ptr, convert("0000000000123456")); DoPointerTest(convert("%#p"), ptr, convert("0X0000000000123456")); DoPointerTest(convert("%lp"), ptr, convert("00123456")); DoPointerTest(convert("%hp"), ptr, convert("00003456")); DoPointerTest(convert("%Lp"), ptr, convert("00123456")); DoI64Test(convert("%I64p"), lptr, "1234567887654321", convert("1234567887654321")); #else Trace("Testing for Non 64 Bit Platforms \n"); DoPointerTest(convert("%p"), NULL, convert("00000000")); DoPointerTest(convert("%p"), ptr, convert("00123456")); DoPointerTest(convert("%9p"), ptr, convert(" 00123456")); DoPointerTest(convert("%09p"), ptr, convert(" 00123456")); DoPointerTest(convert("%-9p"), ptr, convert("00123456 ")); DoPointerTest(convert("%+p"), ptr, convert("00123456")); DoPointerTest(convert("% p"), ptr, convert("00123456")); DoPointerTest(convert("%#p"), ptr, convert("0X00123456")); DoPointerTest(convert("%lp"), ptr, convert("00123456")); DoPointerTest(convert("%hp"), ptr, convert("00003456")); DoPointerTest(convert("%Lp"), ptr, convert("00123456")); DoI64Test(convert("%I64p"), lptr, "1234567887654321", convert("1234567887654321")); #endif PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { if (PAL_Initialize(argc, argv)) { return FAIL; } DoNumTest("1234d", "%i", 1234); DoNumTest("1234d", "%2i", 12); DoNumTest("-1", "%i", -1); DoNumTest("0x1234", "%i", 0x1234); DoNumTest("012", "%i", 10); DoShortNumTest("-1", "%hi", 65535); DoShortNumTest("65536", "%hi", 0); DoNumTest("-1", "%li", -1); DoNumTest("65536", "%li", 65536); DoNumTest("-1", "%Li", -1); DoNumTest("65536", "%Li", 65536); DoI64NumTest("4294967296", "%I64i", I64(4294967296)); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { if (PAL_Initialize(argc, argv)) { return FAIL; } DoNumTest("1234d", "%o", 668); DoNumTest("1234d", "%2o", 10); DoNumTest("-1", "%o", -1); DoNumTest("0x1234", "%o", 0); DoNumTest("012", "%o", 10); DoShortNumTest("-1", "%ho", 65535); DoShortNumTest("200000", "%ho", 0); DoNumTest("-1", "%lo", -1); DoNumTest("200000", "%lo", 65536); DoNumTest("-1", "%Lo", -1); DoNumTest("200000", "%Lo", 65536); DoI64NumTest("40000000000", "%I64o", I64(4294967296)); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { if (PAL_Initialize(argc, argv)) { return FAIL; } DoNumTest(convert("1234d"), convert("%x"), 0x1234d); DoNumTest(convert("1234d"), convert("%2x"), 0x12); DoNumTest(convert("-1"), convert("%x"), -1); DoNumTest(convert("0x1234"), convert("%x"), 0x1234); DoNumTest(convert("012"), convert("%x"), 0x12); DoShortNumTest(convert("-1"), convert("%hx"), 65535); DoShortNumTest(convert("10000"), convert("%hx"), 0); DoNumTest(convert("-1"), convert("%lx"), -1); DoNumTest(convert("10000"), convert("%lx"), 65536); DoNumTest(convert("-1"), convert("%Lx"), -1); DoNumTest(convert("10000"), convert("%Lx"), 65536); DoI64NumTest(convert("100000000"), convert("%I64x"), I64(4294967296)); PAL_Terminate(); return PASS; }
bool Test() { bool fail = false; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); COutStream out; CBufferedOutStream bout; float f = 0; double d = 0; asUINT ui = 0; asINT64 i64 = 0; int i = 0; signed char i8 = 0; asQWORD ui64 = 0; short i16 = 0; unsigned char ui8 = 0; unsigned short ui16 = 0; engine->RegisterGlobalProperty("float f", &f); engine->RegisterGlobalProperty("double d", &d); engine->RegisterGlobalProperty("uint ui", &ui); engine->RegisterGlobalProperty("uint8 ui8", &ui8); engine->RegisterGlobalProperty("uint16 ui16", &ui16); engine->RegisterGlobalProperty("uint64 ui64", &ui64); engine->RegisterGlobalProperty("int i", &i); engine->RegisterGlobalProperty("int8 i8", &i8); engine->RegisterGlobalProperty("int16 i16", &i16); engine->RegisterGlobalProperty("int64 i64", &i64); engine->RegisterGlobalFunction("void TestDouble(double)", asFUNCTION(TestDouble), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestFloat(float)", asFUNCTION(TestFloat), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI64(int16)", asFUNCTION(TestI64), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestInt(int)", asFUNCTION(TestInt), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI16(int16)", asFUNCTION(TestI16), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI8(int8)", asFUNCTION(TestI8), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI64(uint)", asFUNCTION(TestUI64), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUInt(uint)", asFUNCTION(TestUInt), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI16(uint16)", asFUNCTION(TestUI16), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI8(uint8)", asFUNCTION(TestUI8), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestDoubleByRef(double &in)", asFUNCTION(TestDoubleByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestFloatByRef(float &in)", asFUNCTION(TestFloatByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI64ByRef(int &in)", asFUNCTION(TestI64ByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestIntByRef(int &in)", asFUNCTION(TestIntByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI16ByRef(int16 &in)", asFUNCTION(TestI16ByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestI8ByRef(int8 &in)", asFUNCTION(TestI8ByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI64ByRef(uint &in)", asFUNCTION(TestUI64ByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUIntByRef(uint &in)", asFUNCTION(TestUIntByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI16ByRef(uint16 &in)", asFUNCTION(TestUI16ByRef), asCALL_GENERIC); engine->RegisterGlobalFunction("void TestUI8ByRef(uint8 &in)", asFUNCTION(TestUI8ByRef), asCALL_GENERIC); engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "d = double(d);"); if( d != 12.3 ) fail = true; f = 12.3f; engine->ExecuteString(0, "d = double(f);"); if( d != 12.3f ) fail = true; ui = 123; engine->ExecuteString(0, "d = double(ui);"); if( d != 123.0 ) fail = true; ui8 = 123; engine->ExecuteString(0, "d = double(ui8);"); if( d != 123.0 ) fail = true; ui16 = 123; engine->ExecuteString(0, "d = double(ui16);"); if( d != 123.0 ) fail = true; ui64 = 123; engine->ExecuteString(0, "d = double(ui64);"); if( d != 123.0 ) fail = true; i = -123; engine->ExecuteString(0, "d = double(i);"); if( d != -123.0 ) fail = true; i8 = -123; engine->ExecuteString(0, "d = double(i8);"); if( d != -123.0 ) fail = true; i16 = -123; engine->ExecuteString(0, "d = double(i16);"); if( d != -123.0 ) fail = true; i64 = -123; engine->ExecuteString(0, "d = double(i64);"); if( d != -123.0 ) fail = true; ui64 = asQWORD(I64(-1000000000000000000)); double d2 = 18446744073709551615.0 + double(asINT64(ui64)); engine->ExecuteString(0, "d = double(ui64);"); if( d != d2 ) fail = true; d = 12.3; engine->ExecuteString(0, "d = d;"); if( d != 12.3 ) fail = true; f = 12.3f; engine->ExecuteString(0, "d = f;"); if( d != 12.3f ) fail = true; ui = 123; engine->ExecuteString(0, "d = ui;"); if( d != 123.0 ) fail = true; ui8 = 123; engine->ExecuteString(0, "d = ui8;"); if( d != 123.0 ) fail = true; ui16 = 123; engine->ExecuteString(0, "d = ui16;"); if( d != 123.0 ) fail = true; ui64 = 123; engine->ExecuteString(0, "d = ui64;"); if( d != 123.0 ) fail = true; i = -123; engine->ExecuteString(0, "d = i;"); if( d != -123.0 ) fail = true; i8 = -123; engine->ExecuteString(0, "d = i8;"); if( d != -123.0 ) fail = true; i16 = -123; engine->ExecuteString(0, "d = i16;"); if( d != -123.0 ) fail = true; i64 = -123; engine->ExecuteString(0, "d = i64;"); if( d != -123.0 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "d = 12.3; "); if( !CompareDouble(d,12.3) ) fail = true; engine->ExecuteString(0, "d = 12.3f;"); if( !CompareDouble(d,12.3f) ) fail = true; engine->ExecuteString(0, "d = 123; "); if( !CompareDouble(d,123.0) ) fail = true; engine->ExecuteString(0, "d = -123; "); if( !CompareDouble(d,-123.0) ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "f = float(d);"); if( f != 12.3f ) fail = true; f = 12.3f; engine->ExecuteString(0, "f = float(f);"); if( f != 12.3f ) fail = true; ui = 123; engine->ExecuteString(0, "f = float(ui);"); if( f != 123.0f ) fail = true; ui8 = 123; engine->ExecuteString(0, "f = float(ui8);"); if( f != 123.0f ) fail = true; ui16 = 123; engine->ExecuteString(0, "f = float(ui16);"); if( f != 123.0f ) fail = true; ui64 = 123; engine->ExecuteString(0, "f = float(ui64);"); if( f != 123.0f ) fail = true; i = -123; engine->ExecuteString(0, "f = float(i);"); if( f != -123.0f ) fail = true; i8 = -123; engine->ExecuteString(0, "f = float(i8);"); if( f != -123.0f ) fail = true; i16 = -123; engine->ExecuteString(0, "f = float(i16);"); if( f != -123.0f ) fail = true; i64 = -123; engine->ExecuteString(0, "f = float(i64);"); if( f != -123.0f ) fail = true; d = 12.3; engine->ExecuteString(0, "f = d;"); if( f != 12.3f ) fail = true; f = 12.3f; engine->ExecuteString(0, "f = f;"); if( f != 12.3f ) fail = true; ui = 123; engine->ExecuteString(0, "f = ui;"); if( f != 123.0f ) fail = true; ui8 = 123; engine->ExecuteString(0, "f = ui8;"); if( f != 123.0f ) fail = true; ui16 = 123; engine->ExecuteString(0, "f = ui16;"); if( f != 123.0f ) fail = true; ui64 = 123; engine->ExecuteString(0, "f = ui64;"); if( f != 123.0f ) fail = true; i = -123; engine->ExecuteString(0, "f = i;"); if( f != -123.0f ) fail = true; i8 = -123; engine->ExecuteString(0, "f = i8;"); if( f != -123.0f ) fail = true; i16 = -123; engine->ExecuteString(0, "f = i16;"); if( f != -123.0f ) fail = true; i64 = -123; engine->ExecuteString(0, "f = i64;"); if( f != -123.0f ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "f = 12.3; "); if( f != 12.3f ) fail = true; engine->ExecuteString(0, "f = 12.3f;"); if( f != 12.3f ) fail = true; engine->ExecuteString(0, "f = 123; "); if( f != 123.0f ) fail = true; engine->ExecuteString(0, "f = -123; "); if( f != -123.0f ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "i64 = int64(d);"); if( i64 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i64 = int64(f);"); if( i64 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i64 = int64(ui);"); if( i64 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i64 = int64(ui8);"); if( i64 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i64 = int64(ui16);"); if( i64 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i64 = int64(ui64);"); if( i64 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i64 = int64(i);"); if( i64 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i64 = int64(i8);"); if( i64 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i64 = int64(i16);"); if( i64 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i64 = int64(i64);"); if( i64 != -123 ) fail = true; d = 12.3; engine->ExecuteString(0, "i64 = d;"); if( i64 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i64 = f;"); if( i64 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i64 = ui;"); if( i64 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i64 = ui8;"); if( i64 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i64 = ui16;"); if( i64 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i64 = ui64;"); if( i64 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i64 = i;"); if( i64 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i64 = i8;"); if( i64 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i64 = i16;"); if( i64 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i64 = i64;"); if( i64 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "i64 = 12.3; "); if( i64 != 12 ) fail = true; engine->ExecuteString(0, "i64 = -12.3f;"); if( i64 != - 12 ) fail = true; engine->ExecuteString(0, "i64 = 123; "); if( i64 != 123 ) fail = true; engine->ExecuteString(0, "i64 = -123; "); if( i64 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "i = int(d);"); if( i != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i = int(f);"); if( i != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i = int(ui);"); if( i != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i = int(ui8);"); if( i != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i = int(ui16);"); if( i != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i = int(ui64);"); if( i != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i = int(i);"); if( i != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i = int(i8);"); if( i != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i = int(i16);"); if( i != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i = int(i64);"); if( i != -123 ) fail = true; d = 12.3; engine->ExecuteString(0, "i = d;"); if( i != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i = f;"); if( i != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i = ui;"); if( i != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i = ui8;"); if( i != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i = ui16;"); if( i != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i = ui64;"); if( i != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i = i;"); if( i != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i = i8;"); if( i != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i = i16;"); if( i != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i = i64;"); if( i != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "i = 12.3; "); if( i != 12 ) fail = true; engine->ExecuteString(0, "i = -12.3f;"); if( i != - 12 ) fail = true; engine->ExecuteString(0, "i = 123; "); if( i != 123 ) fail = true; engine->ExecuteString(0, "i = -123; "); if( i != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "i8 = int8(d);"); if( i8 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i8 = int8(f);"); if( i8 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i8 = int8(ui);"); if( i8 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i8 = int8(ui8);"); if( i8 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i8 = int8(ui16);"); if( i8 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i8 = int8(ui64);"); if( i8 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i8 = int8(i);"); if( i8 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i8 = int8(i8);"); if( i8 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i8 = int8(i16);"); if( i8 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i8 = int8(i64);"); if( i8 != -123 ) fail = true; d = 12.3; engine->ExecuteString(0, "i8 = d;"); if( i8 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i8 = f;"); if( i8 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i8 = ui;"); if( i8 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i8 = ui8;"); if( i8 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i8 = ui16;"); if( i8 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i8 = ui64;"); if( i8 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i8 = i;"); if( i8 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i8 = i8;"); if( i8 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i8 = i16;"); if( i8 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i8 = i64;"); if( i8 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "i8 = 12.3; "); if( i8 != 12 ) fail = true; engine->ExecuteString(0, "i8 = -12.3f;"); if( i8 != - 12 ) fail = true; engine->ExecuteString(0, "i8 = 123; "); if( i8 != 123 ) fail = true; engine->ExecuteString(0, "i8 = -123; "); if( i8 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "i16 = int16(d);"); if( i16 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i16 = int16(f);"); if( i16 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i16 = int16(ui);"); if( i16 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i16 = int16(ui8);"); if( i16 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i16 = int16(ui16);"); if( i16 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i16 = int16(ui64);"); if( i16 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i16 = int16(i);"); if( i16 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i16 = int16(i8);"); if( i16 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i16 = int16(i16);"); if( i16 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i16 = int16(i64);"); if( i16 != -123 ) fail = true; d = 12.3; engine->ExecuteString(0, "i16 = d;"); if( i16 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "i16 = f;"); if( i16 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "i16 = ui;"); if( i16 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "i16 = ui8;"); if( i16 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "i16 = ui16;"); if( i16 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "i16 = ui64;"); if( i16 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "i16 = i;"); if( i16 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "i16 = i8;"); if( i16 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "i16 = i16;"); if( i16 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "i16 = i64;"); if( i16 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "i16 = 12.3; "); if( i16 != 12 ) fail = true; engine->ExecuteString(0, "i16 = -12.3f;"); if( i16 != - 12 ) fail = true; engine->ExecuteString(0, "i16 = 123; "); if( i16 != 123 ) fail = true; engine->ExecuteString(0, "i16 = -123; "); if( i16 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "ui64 = uint64(d);"); if( ui64 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui64 = uint64(f);"); if( ui64 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "ui64 = uint64(ui);"); if( ui64 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui64 = uint64(ui8);"); if( ui64 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui64 = uint64(ui16);"); if( ui64 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui64 = uint64(ui64);"); if( ui64 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui64 = uint64(i);"); if( ui64 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "ui64 = uint64(i8);"); if( ui64 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "ui64 = uint64(i16);"); if( ui64 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "ui64 = uint64(i64);"); if( ui64 != -123 ) fail = true; d = 12.3; engine->ExecuteString(0, "ui64 = d;"); if( ui64 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui64 = f;"); if( ui64 != - 12 ) fail = true; ui = 123; engine->ExecuteString(0, "ui64 = ui;"); if( ui64 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui64 = ui8;"); if( ui64 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui64 = ui16;"); if( ui64 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui64 = ui64;"); if( ui64 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui64 = i;"); if( ui64 != -123 ) fail = true; i8 = -123; engine->ExecuteString(0, "ui64 = i8;"); if( ui64 != -123 ) fail = true; i16 = -123; engine->ExecuteString(0, "ui64 = i16;"); if( ui64 != -123 ) fail = true; i64 = -123; engine->ExecuteString(0, "ui64 = i64;"); if( ui64 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "ui64 = 12.3; "); if( ui64 != 12 ) fail = true; engine->ExecuteString(0, "ui64 = -12.3f;"); if( ui64 != - 12 ) fail = true; engine->ExecuteString(0, "ui64 = 123; "); if( ui64 != 123 ) fail = true; engine->ExecuteString(0, "ui64 = -123; "); if( ui64 != -123 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "ui = uint(d);"); if( ui != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui = uint(f);"); if( ui != asUINT(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui = uint(ui);"); if( ui != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui = uint(ui8);"); if( ui != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui = uint(ui16);"); if( ui != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui = uint(ui64);"); if( ui != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui = uint(i);"); if( ui != asUINT(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui = uint(i8);"); if( ui != asUINT(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui = uint(i16);"); if( ui != asUINT(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui = uint(i64);"); if( ui != asUINT(-123) ) fail = true; d = 12.3; engine->ExecuteString(0, "ui = d;"); if( ui != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui = f;"); if( ui != asUINT(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui = ui;"); if( ui != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui = ui8;"); if( ui != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui = ui16;"); if( ui != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui = ui64;"); if( ui != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui = i;"); if( ui != asUINT(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui = i8;"); if( ui != asUINT(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui = i16;"); if( ui != asUINT(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui = i64;"); if( ui != asUINT(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "ui = 12.3; "); if( ui != 12 ) fail = true; engine->ExecuteString(0, "ui = -12.3f;"); if( ui != asUINT(-12) ) fail = true; engine->ExecuteString(0, "ui = 123; "); if( ui != 123 ) fail = true; engine->ExecuteString(0, "ui = -123; "); if( ui != asUINT(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "ui8 = uint8(d);"); if( ui8 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui8 = uint8(f);"); if( ui8 != asBYTE(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui8 = uint8(ui);"); if( ui8 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui8 = uint8(ui8);"); if( ui8 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui8 = uint8(ui16);"); if( ui8 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui8 = uint8(ui64);"); if( ui8 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui8 = uint8(i);"); if( ui8 != asBYTE(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui8 = uint8(i8);"); if( ui8 != asBYTE(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui8 = uint8(i16);"); if( ui8 != asBYTE(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui8 = uint8(i64);"); if( ui8 != asBYTE(-123) ) fail = true; d = 12.3; engine->ExecuteString(0, "ui8 = d;"); if( ui8 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui8 = f;"); if( ui8 != asBYTE(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui8 = ui;"); if( ui8 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui8 = ui8;"); if( ui8 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui8 = ui16;"); if( ui8 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui8 = ui64;"); if( ui8 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui8 = i;"); if( ui8 != asBYTE(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui8 = i8;"); if( ui8 != asBYTE(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui8 = i16;"); if( ui8 != asBYTE(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui8 = i64;"); if( ui8 != asBYTE(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "ui8 = 12.3; "); if( ui8 != 12 ) fail = true; engine->ExecuteString(0, "ui8 = -12.3f;"); if( ui8 != asBYTE(-12) ) fail = true; // asBYTE(-12.3f) doesn't seem to produce the same result on MSVC and GNUC engine->ExecuteString(0, "ui8 = 123; "); if( ui8 != 123 ) fail = true; engine->ExecuteString(0, "ui8 = -123; "); if( ui8 != asBYTE(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); d = 12.3; engine->ExecuteString(0, "ui16 = uint16(d);"); if( ui16 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui16 = uint16(f);"); if( ui16 != asWORD(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui16 = uint16(ui);"); if( ui16 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui16 = uint16(ui8);"); if( ui16 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui16 = uint16(ui16);"); if( ui16 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui16 = uint16(ui64);"); if( ui16 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui16 = uint16(i);"); if( ui16 != asWORD(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui16 = uint16(i8);"); if( ui16 != asWORD(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui16 = uint16(i16);"); if( ui16 != asWORD(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui16 = uint16(i64);"); if( ui16 != asWORD(-123) ) fail = true; d = 12.3; engine->ExecuteString(0, "ui16 = d;"); if( ui16 != 12 ) fail = true; f = -12.3f; engine->ExecuteString(0, "ui16 = f;"); if( ui16 != asWORD(-12) ) fail = true; ui = 123; engine->ExecuteString(0, "ui16 = ui;"); if( ui16 != 123 ) fail = true; ui8 = 123; engine->ExecuteString(0, "ui16 = ui8;"); if( ui16 != 123 ) fail = true; ui16 = 123; engine->ExecuteString(0, "ui16 = ui16;"); if( ui16 != 123 ) fail = true; ui64 = 123; engine->ExecuteString(0, "ui16 = ui64;"); if( ui16 != 123 ) fail = true; i = -123; engine->ExecuteString(0, "ui16 = i;"); if( ui16 != asWORD(-123) ) fail = true; i8 = -123; engine->ExecuteString(0, "ui16 = i8;"); if( ui16 != asWORD(-123) ) fail = true; i16 = -123; engine->ExecuteString(0, "ui16 = i16;"); if( ui16 != asWORD(-123) ) fail = true; i64 = -123; engine->ExecuteString(0, "ui16 = i64;"); if( ui16 != asWORD(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "ui16 = 12.3; "); if( ui16 != 12 ) fail = true; engine->ExecuteString(0, "ui16 = -12.3f;"); if( ui16 != asWORD(-12) ) fail = true; // asWORD(-12.3f) doesn't seem to produce the same result on MSVC and GNUC engine->ExecuteString(0, "ui16 = 123; "); if( ui16 != 123 ) fail = true; engine->ExecuteString(0, "ui16 = -123; "); if( ui16 != asWORD(-123) ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); engine->ExecuteString(0, "TestDouble(d); TestFloat(d); TestInt(d); TestI16(d); TestI8(d); TestUInt(d); TestUI16(d); TestUI8(d);"); engine->ExecuteString(0, "TestDouble(f); TestFloat(f); TestInt(f); TestI16(f); TestI8(f); TestUInt(f); TestUI16(f); TestUI8(f);"); engine->ExecuteString(0, "TestDouble(ui); TestFloat(ui); TestInt(ui); TestI16(ui); TestI8(ui); TestUInt(ui); TestUI16(ui); TestUI8(ui);"); engine->ExecuteString(0, "TestDouble(ui8); TestFloat(ui8); TestInt(ui8); TestI16(ui8); TestI8(ui8); TestUInt(ui8); TestUI16(ui8); TestUI8(ui8);"); engine->ExecuteString(0, "TestDouble(ui16); TestFloat(ui16); TestInt(ui16); TestI16(ui16); TestI8(ui16); TestUInt(ui16); TestUI16(ui16); TestUI8(ui16);"); engine->ExecuteString(0, "TestDouble(ui64); TestFloat(ui64); TestInt(ui64); TestI16(ui64); TestI8(ui64); TestUInt(ui64); TestUI16(ui64); TestUI8(ui64);"); engine->ExecuteString(0, "TestDouble(i); TestFloat(i); TestInt(i); TestI16(i); TestI8(i); TestUInt(i); TestUI16(i); TestUI8(i);"); engine->ExecuteString(0, "TestDouble(i8); TestFloat(i8); TestInt(i8); TestI16(i8); TestI8(i8); TestUInt(i8); TestUI16(i8); TestUI8(i8);"); engine->ExecuteString(0, "TestDouble(i16); TestFloat(i16); TestInt(i16); TestI16(i16); TestI8(i16); TestUInt(i16); TestUI16(i16); TestUI8(i16);"); engine->ExecuteString(0, "TestDouble(i64); TestFloat(i64); TestInt(i64); TestI16(i64); TestI8(i64); TestUInt(i64); TestUI16(i64); TestUI8(i64);"); d = 0; i8 = -22; engine->ExecuteString(0, "d = d + i8"); if( d != -22 ) fail = true; engine->ExecuteString(0, "int[] a(1); a[0] = 0; a[0] == 1"); engine->ExecuteString(0, "ui + i"); engine->ExecuteString(0, "int a = 0, ui = 0; (a+ui)&1;"); // There is no bitwise conversion between uint to float anymore // f = 0; engine->ExecuteString(0, "f = float(0x3f800000)"); if( f != 1 ) fail = true; bout.buffer = ""; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); engine->ExecuteString(0, "i == ui"); if( bout.buffer != "ExecuteString (1, 3) : Warning : Signed/Unsigned mismatch\n" ) fail = true; bout.buffer = ""; int r; // TODO: PPC: We cannot allow this with PPC // Allow the conversion of a type to another even for reference parameters (C++ doesn't allow this) r = engine->ExecuteString(0, "TestDoubleByRef(d); TestFloatByRef(d); TestIntByRef(d); TestI16ByRef(d); TestI8ByRef(d); TestUIntByRef(d); TestUI16ByRef(d); TestUI8ByRef(d);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(f); TestFloatByRef(f); TestIntByRef(f); TestI16ByRef(f); TestI8ByRef(f); TestUIntByRef(f); TestUI16ByRef(f); TestUI8ByRef(f);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(ui); TestFloatByRef(ui); TestIntByRef(ui); TestI16ByRef(ui); TestI8ByRef(ui); TestUIntByRef(ui); TestUI16ByRef(ui); TestUI8ByRef(ui);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(ui8); TestFloatByRef(ui8); TestIntByRef(ui8); TestI16ByRef(ui8); TestI8ByRef(ui8); TestUIntByRef(ui8); TestUI16ByRef(ui8); TestUI8ByRef(ui8);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(ui16); TestFloatByRef(ui16); TestIntByRef(ui16); TestI16ByRef(ui16); TestI8ByRef(ui16); TestUIntByRef(ui16); TestUI16ByRef(ui16); TestUI8ByRef(ui16);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(ui64); TestFloatByRef(ui64); TestIntByRef(ui64); TestI16ByRef(ui64); TestI8ByRef(ui64); TestUIntByRef(ui64); TestUI16ByRef(ui64); TestUI8ByRef(ui64);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(i); TestFloatByRef(i); TestIntByRef(i); TestI16ByRef(i); TestI8ByRef(i); TestUIntByRef(i); TestUI16ByRef(i); TestUI8ByRef(i);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(i8); TestFloatByRef(i8); TestIntByRef(i8); TestI16ByRef(i8); TestI8ByRef(i8); TestUIntByRef(i8); TestUI16ByRef(i8); TestUI8ByRef(i8);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(i16); TestFloatByRef(i16); TestIntByRef(i16); TestI16ByRef(i16); TestI8ByRef(i16); TestUIntByRef(i16); TestUI16ByRef(i16); TestUI8ByRef(i16);"); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestDoubleByRef(i64); TestFloatByRef(i64); TestIntByRef(i64); TestI16ByRef(i64); TestI8ByRef(i64); TestUIntByRef(i64); TestUI16ByRef(i64); TestUI8ByRef(i64);"); if( r < 0 ) fail = true; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection("script", script, strlen(script)); mod->Build(); // This test is to make sure that the float is in fact converted to a double engine->ExecuteString(0, "TestScript();"); // Make sure uint and int can be converted to bits when using the ~ operator engine->ExecuteString(0, "uint x = 0x34; x = ~x;"); engine->ExecuteString(0, "int x = 0x34; x = ~x;"); engine->Release(); if( fail ) printf("%s: failed\n", TESTNAME); // Success return fail; }
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! */ #include <stdint.h> #include <assert.h> #include <string.h> #include "Common/Tcdefs.h" #include "Common/Endian.h" #include "Sha3.h" /* constants */ #define NumberOfRounds 24 /* SHA3 constants for 24 rounds */ static uint64_t Sha3RoundConstants[NumberOfRounds] = { I64(0x0000000000000001), I64(0x0000000000008082), I64(0x800000000000808A), I64(0x8000000080008000), I64(0x000000000000808B), I64(0x0000000080000001), I64(0x8000000080008081), I64(0x8000000000008009), I64(0x000000000000008A), I64(0x0000000000000088), I64(0x0000000080008009), I64(0x000000008000000A), I64(0x000000008000808B), I64(0x800000000000008B), I64(0x8000000000008089), I64(0x8000000000008003), I64(0x8000000000008002), I64(0x8000000000000080), I64(0x000000000000800A), I64(0x800000008000000A), I64(0x8000000080008081), I64(0x8000000000008080), I64(0x0000000080000001), I64(0x8000000080008008) }; /* Initializing a SHA3 context for given number of output bits */ void Sha3Init(sha3_ctx *ctx) { unsigned bits = 256; /* NB: The Keccak capacity parameter = bits * 2 */ unsigned rate = 1600 - bits * 2; memset(ctx, 0, sizeof(sha3_ctx));
/** * The core transformation. Process a 512-bit block. * * @param hash algorithm state * @param block the message block to process */ static void whirlpool_process_block(uint64_t *hash, uint64_t* p_block) { int i; /* loop counter */ uint64_t K1[8]; /* key used in even rounds */ uint64_t K2[8]; /* key used in odd rounds */ uint64_t state1[8]; /* state used in even rounds */ uint64_t state2[8]; /* state used in odd rounds */ /* the number of rounds of the internal dedicated block cipher */ const int number_of_rounds = 10; /* array used in the rounds */ static const uint64_t rc[10] = { I64(0x1823c6e887b8014f), I64(0x36a6d2f5796f9152), I64(0x60bc9b8ea30c7b35), I64(0x1de0d7c22e4bfe57), I64(0x157737e59ff04ada), I64(0x58c9290ab1a06b85), I64(0xbd5d10f4cb3e0567), I64(0xe427418ba77d95d8), I64(0xfbee7c66dd17479e), I64(0xca2dbf07ad5a8333) }; /* map the message buffer to a block */ for(i = 0; i < 8; i++) { /* store K^0 and xor it with intermediate hash state */ state1[i] = hash[i] = be2me_64(p_block[i]) ^ (K1[i] = hash[i]); } /* iterate over algorithm rounds */ for(i = 0; i < number_of_rounds; i++) { /* compute K^i from K^{i-1} */ K2[0] = WHIRLPOOL_OP(K1, 0) ^ rc[i]; K2[1] = WHIRLPOOL_OP(K1, 1); K2[2] = WHIRLPOOL_OP(K1, 2); K2[3] = WHIRLPOOL_OP(K1, 3); K2[4] = WHIRLPOOL_OP(K1, 4); K2[5] = WHIRLPOOL_OP(K1, 5); K2[6] = WHIRLPOOL_OP(K1, 6); K2[7] = WHIRLPOOL_OP(K1, 7); /* apply the i-th round transformation */ state2[0] = WHIRLPOOL_OP(state1, 0) ^ K2[0]; state2[1] = WHIRLPOOL_OP(state1, 1) ^ K2[1]; state2[2] = WHIRLPOOL_OP(state1, 2) ^ K2[2]; state2[3] = WHIRLPOOL_OP(state1, 3) ^ K2[3]; state2[4] = WHIRLPOOL_OP(state1, 4) ^ K2[4]; state2[5] = WHIRLPOOL_OP(state1, 5) ^ K2[5]; state2[6] = WHIRLPOOL_OP(state1, 6) ^ K2[6]; state2[7] = WHIRLPOOL_OP(state1, 7) ^ K2[7]; i++; /* compute K^i from K^{i-1} */ K1[0] = WHIRLPOOL_OP(K2, 0) ^ rc[i]; K1[1] = WHIRLPOOL_OP(K2, 1); K1[2] = WHIRLPOOL_OP(K2, 2); K1[3] = WHIRLPOOL_OP(K2, 3); K1[4] = WHIRLPOOL_OP(K2, 4); K1[5] = WHIRLPOOL_OP(K2, 5); K1[6] = WHIRLPOOL_OP(K2, 6); K1[7] = WHIRLPOOL_OP(K2, 7); /* apply the i-th round transformation */ state1[0] = WHIRLPOOL_OP(state2, 0) ^ K1[0]; state1[1] = WHIRLPOOL_OP(state2, 1) ^ K1[1]; state1[2] = WHIRLPOOL_OP(state2, 2) ^ K1[2]; state1[3] = WHIRLPOOL_OP(state2, 3) ^ K1[3]; state1[4] = WHIRLPOOL_OP(state2, 4) ^ K1[4]; state1[5] = WHIRLPOOL_OP(state2, 5) ^ K1[5]; state1[6] = WHIRLPOOL_OP(state2, 6) ^ K1[6]; state1[7] = WHIRLPOOL_OP(state2, 7) ^ K1[7]; } /* apply the Miyaguchi-Preneel compression function */ hash[0] ^= state1[0]; hash[1] ^= state1[1]; hash[2] ^= state1[2]; hash[3] ^= state1[3]; hash[4] ^= state1[4]; hash[5] ^= state1[5]; hash[6] ^= state1[6]; hash[7] ^= state1[7]; }
void WINAPI UnixTimeToFileTime( DWORD time, FILETIME * ft ) { *(__int64*)ft = EPOCH_BIAS + time * I64(10000000); }
static asINT64 reti64() { return I64(0x102030405); }