* fix to_ieee754

meow
Dominika 2022-02-13 03:17:34 +01:00
parent 43653c1843
commit 4bdc24558e
3 changed files with 34 additions and 1 deletions

23
src/chunk.sh Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
# chunk.sh - misc chunk functions
function chunk_header() {
chunk="7fff" # amount of blocks, doesnt matter
chunk+="08" # palette - bits per block
chunk+="$(int2varint ${#palette[@]})" # palette - entries amount
chunk+="${palette[@]}"
}
function chunk_footer() {
chunk+="0001" # biome palette
chunk+="$(repeat 26 "0000000000000001")" # set biome to plains
}
function chunkfix() {
sed -E 's/(.{8})(.{8})/\2\1/;'
}
function hexchunkfix() {
sed -E 's/(.{16})(.{16})/\2\1/;'
}

View File

@ -157,8 +157,12 @@ function to_ieee754() {
i=$((i+1))
m=$((m*2))
done
# we need to lie and tell Bash that this string is decimal, even though it's binary
# otherwise, it will interpret this as octal
mantissa=$(printf "1%010d" $(hex2bin $(printf "%x" $i)))
# shh, nobody tell Bash
mantissa=$(printf "1%010d" $((10#$(hex2bin $(printf "%x" $i)))))
# leading zeroes kept screwing me over, I'm hardcoding 1 and -1
if [[ $n == -1 ]]; then

6
src/misc.sh Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
# misc.sh - helper functions
function repeat() {
printf -- "$2%.0s" $(seq 1 $1)
}