special int and float instructions
This commit is contained in:
parent
adff19b765
commit
7abac5e995
@ -164,6 +164,10 @@ instructionFloatShove = instructionShove float
|
|||||||
instructionFloatIsStackEmpty :: State -> State
|
instructionFloatIsStackEmpty :: State -> State
|
||||||
instructionFloatIsStackEmpty = instructionIsStackEmpty float
|
instructionFloatIsStackEmpty = instructionIsStackEmpty float
|
||||||
|
|
||||||
|
-- |Duplicate the top N items from the float stack based on the top int from the int stack.
|
||||||
|
instructionFloatDupItems :: State -> State
|
||||||
|
instructionFloatDupItems = instructionDupItems float
|
||||||
|
|
||||||
-- |Pushes the sin of the top float to the float stack.
|
-- |Pushes the sin of the top float to the float stack.
|
||||||
instructionFloatSin :: State -> State
|
instructionFloatSin :: State -> State
|
||||||
instructionFloatSin state@(State {_float = f1 : fs}) = state {_float = sin f1 : fs}
|
instructionFloatSin state@(State {_float = f1 : fs}) = state {_float = sin f1 : fs}
|
||||||
@ -179,9 +183,40 @@ instructionFloatTan :: State -> State
|
|||||||
instructionFloatTan state@(State {_float = f1 : fs}) = state {_float = tan f1 : fs}
|
instructionFloatTan state@(State {_float = f1 : fs}) = state {_float = tan f1 : fs}
|
||||||
instructionFloatTan state = state
|
instructionFloatTan state = state
|
||||||
|
|
||||||
-- |Duplicate the top N items from the float stack based on the top int from the int stack.
|
-- |Pushes the absolute value of the top float to the float stack.
|
||||||
instructionFloatDupItems :: State -> State
|
instructionFloatAbs :: State -> State
|
||||||
instructionFloatDupItems = instructionDupItems float
|
instructionFloatAbs state@(State {_float = f1 : fs}) = state {_float = abs f1 : fs}
|
||||||
|
instructionFloatAbs state = state
|
||||||
|
|
||||||
|
-- |Pushes the exponential of the top float to the float stack.
|
||||||
|
instructionFloatExp :: State -> State
|
||||||
|
instructionFloatExp state@(State {_float = f1 : fs}) = state {_float = exp f1 : fs}
|
||||||
|
instructionFloatExp state = state
|
||||||
|
|
||||||
|
-- |Pushes the log of the top float to the float stack.
|
||||||
|
instructionFloatLog :: State -> State
|
||||||
|
instructionFloatLog state@(State {_float = f1 : fs}) = state {_float = log f1 : fs}
|
||||||
|
instructionFloatLog state = state
|
||||||
|
|
||||||
|
-- |Pushes the squared value of the top float to the float stack.
|
||||||
|
instructionFloatSquare :: State -> State
|
||||||
|
instructionFloatSquare state@(State {_float = f1 : fs}) = state {_float = f1 ^ (2 :: Int) : fs}
|
||||||
|
instructionFloatSquare state = state
|
||||||
|
|
||||||
|
-- |Pushes the cubed value of the top float to the float stack.
|
||||||
|
instructionFloatCube :: State -> State
|
||||||
|
instructionFloatCube state@(State {_float = f1 : fs}) = state {_float = f1 ^ (3 :: Int) : fs}
|
||||||
|
instructionFloatCube state = state
|
||||||
|
|
||||||
|
-- |Pushes the square rooted value of the top float to the float stack.
|
||||||
|
instructionFloatSqrt :: State -> State
|
||||||
|
instructionFloatSqrt state@(State {_float = f1 : fs}) = state {_float = sqrt f1 : fs}
|
||||||
|
instructionFloatSqrt state = state
|
||||||
|
|
||||||
|
-- |Pushes the top float with its sign reversed to the top of the float stack.
|
||||||
|
instructionFloatReverseSign :: State -> State
|
||||||
|
instructionFloatReverseSign state@(State {_float = f1 : fs}) = state {_float = (-1) * f1 : fs}
|
||||||
|
instructionFloatReverseSign state = state
|
||||||
|
|
||||||
allFloatInstructions :: [Gene]
|
allFloatInstructions :: [Gene]
|
||||||
allFloatInstructions = map StateFunc ($(functionExtractor "instruction"))
|
allFloatInstructions = map StateFunc ($(functionExtractor "instruction"))
|
||||||
|
@ -168,5 +168,55 @@ instructionIntIsStackEmpty = instructionIsStackEmpty int
|
|||||||
instructionIntDupItems :: State -> State
|
instructionIntDupItems :: State -> State
|
||||||
instructionIntDupItems = instructionDupItems int
|
instructionIntDupItems = instructionDupItems int
|
||||||
|
|
||||||
|
-- |Pushes the sin of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntSin :: State -> State
|
||||||
|
instructionIntSin state@(State {_int = i1 : is}) = state {_int = round (sin (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntSin state = state
|
||||||
|
|
||||||
|
-- |Pushes the cos of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntCos :: State -> State
|
||||||
|
instructionIntCos state@(State {_int = i1 : is}) = state {_int = round (cos (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntCos state = state
|
||||||
|
|
||||||
|
-- |Pushes the tan of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntTan :: State -> State
|
||||||
|
instructionIntTan state@(State {_int = i1 : is}) = state {_int = round (tan (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntTan state = state
|
||||||
|
|
||||||
|
-- |Pushes the absolute value of the top int to the int stack.
|
||||||
|
instructionIntAbs :: State -> State
|
||||||
|
instructionIntAbs state@(State {_int = i1 : is}) = state {_int = abs i1 : is}
|
||||||
|
instructionIntAbs state = state
|
||||||
|
|
||||||
|
-- |Pushes the exponential of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntExp :: State -> State
|
||||||
|
instructionIntExp state@(State {_int = i1 : is}) = state {_int = round (exp (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntExp state = state
|
||||||
|
|
||||||
|
-- |Pushes the log of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntLog :: State -> State
|
||||||
|
instructionIntLog state@(State {_int = i1 : is}) = state {_int = round (log (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntLog state = state
|
||||||
|
|
||||||
|
-- |Pushes the squared value of the top int to the int stack.
|
||||||
|
instructionIntSquare :: State -> State
|
||||||
|
instructionIntSquare state@(State {_int = i1 : is}) = state {_int = i1 ^ (2 :: Int) : is}
|
||||||
|
instructionIntSquare state = state
|
||||||
|
|
||||||
|
-- |Pushes the cubed value of the top int to the int stack.
|
||||||
|
instructionIntCube :: State -> State
|
||||||
|
instructionIntCube state@(State {_int = i1 : is}) = state {_int = i1 ^ (3 :: Int) : is}
|
||||||
|
instructionIntCube state = state
|
||||||
|
|
||||||
|
-- |Pushes the square rooted value of the top int to the int stack. Rounding if needed.
|
||||||
|
instructionIntSqrt :: State -> State
|
||||||
|
instructionIntSqrt state@(State {_int = i1 : is}) = state {_int = round (sqrt (fromIntegral @Integer @Double i1)) : is}
|
||||||
|
instructionIntSqrt state = state
|
||||||
|
|
||||||
|
-- |Pushes the top int with its sign reversed to the top of the int stack.
|
||||||
|
instructionIntReverseSign :: State -> State
|
||||||
|
instructionIntReverseSign state@(State {_int = i1 : is}) = state {_int = (-1) * i1 : is}
|
||||||
|
instructionIntReverseSign state = state
|
||||||
|
|
||||||
allIntInstructions :: [Gene]
|
allIntInstructions :: [Gene]
|
||||||
allIntInstructions = map StateFunc ($(functionExtractor "instruction"))
|
allIntInstructions = map StateFunc ($(functionExtractor "instruction"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user