* yet another ieee754 fix

This commit is contained in:
Dominika 2022-02-14 01:54:42 +01:00
parent 59d995019d
commit 2d94cc3472

View file

@ -164,11 +164,13 @@ function to_ieee754() {
# shh, nobody tell Bash # shh, nobody tell Bash
mantissa=$(printf "1%010d" $((10#$(hex2bin $(printf "%x" $i))))) 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.. and 0
if [[ $n == -1 ]]; then if [[ $n == -1 ]]; then
printf "bff0000000000000" printf "bff0000000000000"
elif [[ $n == 1 ]]; then elif [[ $n == 1 ]]; then
printf "3ff0000000000000" printf "3ff0000000000000"
elif [[ $n == 0 ]]; then
printf "0000000000000000"
else else
res=$sign$mantissa$(printf "%0$((i+1))d" $(hex2bin $(printf "%x" $((n-m))) | sed -E 's/^0*//')) res=$sign$mantissa$(printf "%0$((i+1))d" $(hex2bin $(printf "%x" $((n-m))) | sed -E 's/^0*//'))
printf "%x" $((2#$res$(repeat $((64-$(echo -n $res | wc -c))) 0))) printf "%x" $((2#$res$(repeat $((64-$(echo -n $res | wc -c))) 0)))