From 5fb5ea9d7d19d70b132a228ec755c1da71d9d2cd Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Sun, 19 Jan 2025 21:55:56 -0600 Subject: [PATCH] add more floatinstructions --- src/Instructions/FloatInstructions.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Instructions/FloatInstructions.hs b/src/Instructions/FloatInstructions.hs index caf2589..df86fbb 100644 --- a/src/Instructions/FloatInstructions.hs +++ b/src/Instructions/FloatInstructions.hs @@ -1,8 +1,19 @@ module Instructions.FloatInstructions where +import Data.Fixed (mod') import Instructions.GenericInstructions import State +-- stopped here for now: https://erp12.github.io/pyshgp/html/core_instructions.html#bool-invert-first-then-and + +instructionFloatFromInt :: State -> State +instructionFloatFromInt state@(State {_float = fs, _int = (i : is)}) = state {_float = (fromIntegral i :: Float) : fs, _int = is} +instructionFloatFromInt state = state + +instructionFloatFromBool :: State -> State +instructionFloatFromBool state@(State {_bool = (b : bs), _float = fs}) = state {_bool = bs, _float = (if b then 1.0 else 0.0) : fs} +instructionFloatFromBool state = state + instructionFloatAdd :: State -> State instructionFloatAdd state@(State {_float = (f1 : f2 : fs)}) = state {_float = f2 + f1 : fs} instructionFloatAdd state = state @@ -19,6 +30,10 @@ instructionFloatDiv :: State -> State instructionFloatDiv state@(State {_float = (f1 : f2 : fs)}) = state {_float = if f1 /= 0 then f2 / f1 : fs else f1 : f2 : fs} instructionFloatDiv state = state +instructionFloatMod :: State -> State +instructionFloatMod state@(State {_float = (f1 : f2 : fs)}) = state {_float = f2 `mod'` f1 : fs} +instructionFloatMod state = state + instructionFloatMin :: State -> State instructionFloatMin state@(State {_float = (f1 : f2 : fs)}) = state {_float = min f1 f2 : fs} instructionFloatMin state = state