From 4bdc24558e29b7ea3e617e3993d80061b936b881 Mon Sep 17 00:00:00 2001 From: Dominika Date: Sun, 13 Feb 2022 03:17:34 +0100 Subject: [PATCH] * fix to_ieee754 --- src/chunk.sh | 23 +++++++++++++++++++++++ src/int.sh | 6 +++++- src/misc.sh | 6 ++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/chunk.sh create mode 100644 src/misc.sh diff --git a/src/chunk.sh b/src/chunk.sh new file mode 100644 index 0000000..59d9a74 --- /dev/null +++ b/src/chunk.sh @@ -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/;' +} diff --git a/src/int.sh b/src/int.sh index a6245ab..5491538 100644 --- a/src/int.sh +++ b/src/int.sh @@ -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 diff --git a/src/misc.sh b/src/misc.sh new file mode 100644 index 0000000..507f13a --- /dev/null +++ b/src/misc.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# misc.sh - helper functions + +function repeat() { + printf -- "$2%.0s" $(seq 1 $1) +}