Simplified itoa
This commit is contained in:
parent
87ae78c86a
commit
76c916018a
@ -6,6 +6,7 @@ A simple programming language.
|
|||||||
|
|
||||||
* Fast compilation
|
* Fast compilation
|
||||||
* Small binaries
|
* Small binaries
|
||||||
|
* High performance
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ import sys
|
|||||||
number(x) {
|
number(x) {
|
||||||
length := 20
|
length := 20
|
||||||
buffer := mem.alloc(length)
|
buffer := mem.alloc(length)
|
||||||
itoa(x, buffer, length)
|
tmp := itoa(x, buffer, length)
|
||||||
|
sys.write(1, tmp, buffer + length - tmp)
|
||||||
mem.free(buffer, length)
|
mem.free(buffer, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +20,7 @@ itoa(x, buffer, length) {
|
|||||||
tmp[0] = '0' + digit
|
tmp[0] = '0' + digit
|
||||||
|
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
sys.write(1, tmp, end - tmp)
|
return tmp
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user