* fix to_ieee754
This commit is contained in:
parent
43653c1843
commit
4bdc24558e
23
src/chunk.sh
Normal file
23
src/chunk.sh
Normal 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/;'
|
||||||
|
}
|
|
@ -157,8 +157,12 @@ function to_ieee754() {
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
m=$((m*2))
|
m=$((m*2))
|
||||||
done
|
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
|
# leading zeroes kept screwing me over, I'm hardcoding 1 and -1
|
||||||
if [[ $n == -1 ]]; then
|
if [[ $n == -1 ]]; then
|
||||||
|
|
6
src/misc.sh
Normal file
6
src/misc.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# misc.sh - helper functions
|
||||||
|
|
||||||
|
function repeat() {
|
||||||
|
printf -- "$2%.0s" $(seq 1 $1)
|
||||||
|
}
|
Loading…
Reference in a new issue