Skip to content

Commit

Permalink
correct conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChippyPlus committed Oct 28, 2024
1 parent e2c5f0e commit 4885745
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .kotlin/errors/errors-1730095326003.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kotlin version: 2.1.0-Beta2
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: Unknown. The daemon process output:
1. Kotlin compile daemon is ready

2 changes: 0 additions & 2 deletions main.kar
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
lit f1 25
call strings.cheekyfloat
9 changes: 7 additions & 2 deletions src/main/kotlin/internals/instructions/xFloats/ftoi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import data.registers.RegisterType
import registers

fun XFloats.ftoi(registerX: RegisterType, register: RegisterType) {
val valueFloat = registers.readX(registerX)
registers.write(register, valueFloat.value)
val valueLong = registers.readX(registerX)

if (valueLong.isDouble) {
registers.writeX(registerX, Double.fromBits(valueLong.value).toLong())
} else {
registers.writeX(registerX, Float.fromBits(valueLong.value.toInt()).toLong())
}
}
11 changes: 8 additions & 3 deletions src/main/kotlin/internals/instructions/xFloats/itof.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package internals.instructions.xFloats

import data.registers.FDRegister
import data.registers.RegisterType
import registers

fun XFloats.itof(register: RegisterType, registerX: RegisterType) {
val valueLong = registers.read(register)
registers.writeX(registerX, FDRegister(false, valueLong))
val valueLong = registers.readX(register)
if (valueLong.isDouble) {
registers.writeX(registerX, valueLong.value.toDouble().toBits())
} else {
registers.writeX(registerX, valueLong.value.toFloat().toBits().toLong())
}


}

0 comments on commit 4885745

Please sign in to comment.