This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| char * numberAsString(uint64_t num) { | |
| static char result[] = "+1.234567890123456e-123"; | |
| char sign = (num & 0x8000000000000000L) ? '-' : '+'; | |
| uint16_t scale = (num >> 50) & 0x1fff; | |
| if (scale << 2 == 0x7ff0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Bit 63 = sign | |
| Subnormal | |
| 0.0-9.999 999 999 999 999E-511 | |
| Stored as uint64 | |
| Normal fp | |
| Bit 62-53 = exponent | |
| Bit 52-0 = mantissa | |
| Mantissa range 0-8 999 999 999 999 999 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Decimal 64 bit numbers that make sense | |
| Format: | |
| ======= | |
| seeeeeee eepmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm | |
| s = sign bit | |
| e = 10-bit exponent (with p) | |
| p = lowest bit of exponent or highest bit of mantissa (subnormal numbers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; ModuleID = 'integer.dodo' | |
| ; Function Attrs: noinline nounwind | |
| define void @int32() { | |
| %frame = alloca i8*, align 8 | |
| %context = alloca i8*, align 8 | |
| br label %test | |
| plus: | |
| %plus1 = load i8*, i8** %frame, align 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -> 0x100000ee4 <+5>: callq 0x100000f74 ; symbol stub for: malloc | |
| 0x100000ee9 <+10>: addq $0x10, %rsp | |
| 0x100000eed <+14>: cmpq $0x0, %rax | |
| 0x100000ef1 <+18>: je 0x100000f3b ; Integer_bits_32_outofmemory | |
| Target 0: (int32) stopped. | |
| (lldb) reg read rbp rsp | |
| rbp = 0x00007ffeefbff9e0 | |
| rsp = 0x00007ffeefbff9d8 | |
| (lldb) n | |
| Process 23851 stopped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .intel_syntax noprefix | |
| _add: | |
| mov eax, edi | |
| add eax, esi | |
| jo plus_overflow | |
| jmp r8 | |
| plus_overflow: | |
| jmp r9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ 98%] Built target compiler | |
| Scanning dependencies of target zig0 | |
| [ 98%] Building CXX object CMakeFiles/zig0.dir/src/main.cpp.o | |
| [ 99%] Building CXX object CMakeFiles/zig0.dir/src/userland.cpp.o | |
| [ 99%] Linking CXX executable zig0 | |
| [ 99%] Built target zig0 | |
| Scanning dependencies of target userland_target | |
| [ 99%] Generating userland.o | |
| ar rcs /Users/jido/dev/github/zig/libuserland.a /Users/jido/dev/github/zig/userland.o /Users/jido/Library/Application Support/zig/stage1/o/Kw399qJMMhP1xxYkT-9eyTN-lrfoF9WqGdLNtnNfyyKQhXGVkyyKpvSaF-xJEXD8/compiler_rt.o | |
| [ 99%] Built target userland_target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef positmacros_h | |
| #define positmacros_h | |
| #ifdef __cplusplus | |
| extern "C"{ | |
| #endif | |
| #include <stdint.h> | |
| #define INT8_MASK 0x7f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| edition = "2020" | |
| name = "prime_factors" | |
| version = "1.1.1" | |
| [dependencies] | |
| rand = "0.7.3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Note: this was tested on Arm64. It should work on any common 64 bit architecture. | |
| # Note 2: typemin(Int64) means NaN and is not handled by the function. | |
| extend64to128 = function(w :: Int64) | |
| x = abs(w) | |
| big = (x << 1) >> 63 # -1 if the number is extended (bit 62 set) | |
| neg = (w >>> 62) | 1 # 11 for negative number, 01 for positive | |
| rg = leading_zeros(~x << 1) # count the regime bits | |
| # That's where it really starts. |