Signed integer representation

This commit is contained in:
Sasha Koshka 2022-11-22 01:02:42 -05:00
parent a47445f494
commit 0ce136585b
2 changed files with 35 additions and 6 deletions

23
draw.go
View File

@ -147,6 +147,8 @@ func drawHexadecimal (xOffset, yOffset int, number uint64) {
application.SetColor(xOffset, yOffset, stone.ColorBlue)
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
number = drawSign(xOffset, yOffset, number)
for x := 0; x < 16; x ++ {
bitOffset -= 4
@ -181,6 +183,8 @@ func drawDecimal (xOffset, yOffset int, number uint64) {
application.SetColor(xOffset, yOffset, stone.ColorBlue)
application.SetColor(xOffset + 1, yOffset, stone.ColorBlue)
number = drawSign(xOffset, yOffset, number)
for x := 0; x < 20; x ++ {
trueX := x + xOffset + 5
character := rune((number / divisor) % 10) + '0'
@ -230,3 +234,22 @@ func drawOctal (xOffset, yOffset int, number uint64) {
}
}
}
func drawSign (xOffset, yOffset int, number uint64) (alteredNumber uint64) {
alteredNumber = number
if showSigned {
if int64(alteredNumber) >= 0 {
application.SetRune(xOffset + 3, yOffset, '+')
application.SetColor (
xOffset + 3, yOffset, stone.ColorGreen)
} else {
application.SetRune(xOffset + 3, yOffset, '-')
application.SetColor (
xOffset + 3, yOffset, stone.ColorRed)
alteredNumber = uint64(int64(number) * -1)
}
}
return
}

18
main.go
View File

@ -15,7 +15,8 @@ var application = &stone.Application { }
var expressionRoot Expression
var inputBuffer stone.DamageBuffer
var showLeftColumn bool
var showEndResult bool
var showEndResult bool = true
var showSigned bool = true
func main () {
application.SetTitle("MathPan")
@ -81,11 +82,6 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
case stone.KeyTab:
showEndResult = !showEndResult
redraw()
application.Draw()
case stone.KeyDelete:
if selectedExpression == nil { break }
parent := selectedExpression.Parent()
@ -211,6 +207,16 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
case 's':
showSigned = !showSigned
redraw()
application.Draw()
case stone.KeyTab:
showEndResult = !showEndResult
redraw()
application.Draw()
}
}