hex.input_dec_int_until¶
dst[:n] = the signed decimal number read from input (two’s complement, mod 16^n).
Reads an optional leading '-', then ASCII '0'..'9', and STOPS at the first non-digit byte, which gets stored in stop_byte[:2] (note that a leading '+' stops with dst=0). The primitive behind hex.input_dec_int.
Signature¶
def input_dec_int_until n, dst, stop_byte @ sign_hi, do_minus, loop, digit_lo, add_digit, finish, digit, neg, end { ... }
Defined in hex/input.fj — lines 126–156 (view on GitHub).
Complexity¶
Time:
~ nd(10@+39) (d = number of digits)Space:
~ n(10.5@+149)
See the complexity glossary for what @, w, dw, dbit, n mean.
Requires init¶
The following must be initialised before this macro is invoked:
hex.init
Source¶
Click to view the macro body
def input_dec_int_until n, dst, stop_byte @ sign_hi, do_minus, loop, digit_lo, add_digit, finish, digit, neg, end {
.zero n, dst
.zero n, digit
bit.zero neg
.input stop_byte
.if_flags stop_byte+dw, 1<<2, loop, sign_hi // high nibble 2 -> maybe '-'
sign_hi:
.if_flags stop_byte, 1<<0xD, loop, do_minus // '-' (0x2D) negates; else it's the stop byte
do_minus:
bit.not neg
.input stop_byte
loop:
.if_flags stop_byte+dw, 1<<3, finish, digit_lo // high nibble != 3 -> not '0'-'9' -> stop
digit_lo:
.if_flags stop_byte, (1<<10)-1, finish, add_digit
add_digit:
.mul10 n, dst
.zero digit
.xor digit, stop_byte
.add n, dst, digit
.input stop_byte
;loop
finish:
bit.if0 neg, end
.neg n, dst
;end
digit: hex.vec n
neg: bit.bit
end:
}
Depends on¶
Used by¶
Example uses¶
hex.input_dec_intinhex/input.fj
← Previous: hex.input_dec_uint_until
Next: hex.input_dec_uint →