Better floating point readout

This commit is contained in:
Sasha Koshka 2022-11-23 11:45:31 -05:00
parent 8c3ce9a937
commit cf10dde21a
1 changed files with 26 additions and 7 deletions

33
draw.go
View File

@ -136,13 +136,32 @@ func drawNumberReadoutsFloat () {
application.SetDot((25 - len(err.Error())) / 2, height - 6)
fmt.Fprint(application, err.Error())
} else {
// TODO: display floats in these radixes. ignore the whole
// signs thing. floats are always signed so we need to always
// display a sign.
// drawHexadecimal (0, height - 10, uint64(number))
// drawDecimal (0, height - 8, uint64(number))
// drawOctal (0, height - 6, uint64(number))
drawBinary (0, height - 4, math.Float64bits(number))
firstHalf := int64(math.Floor(number))
secondHalf := (number - math.Floor(number))
application.SetDot(0, height - 7)
fmt.Fprint(application, "10")
application.SetColor(0, height - 7, stone.ColorBlue)
application.SetColor(1, height - 7, stone.ColorBlue)
application.SetDot(3, height - 7)
fmt.Fprintf(application, "%+d", firstHalf)
application.SetRune(3, height - 6, '.')
for index := 4; index < 25; index ++ {
secondHalf *= 10
secondHalf = math.Mod(secondHalf, 10)
digit := rune(secondHalf) + '0'
application.SetRune(index, height - 6, digit)
}
drawBinary(0, height - 4, math.Float64bits(number))
if math.Signbit(number) {
application.SetColor(3, height - 7, stone.ColorRed)
} else {
application.SetColor(3, height - 7, stone.ColorGreen)
}
}
}