Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 154 ' ===============================================================================================================================
- 155 ' #MATH# ========================================================================================================================
- 156 'init
- 157 def fnMax(x%,y%)=(x%>=y%)*x% + (x%<y%)*y%
- 158 def fnMin(x%,y%)=(x%<=y%)*x% + (x%>y%)*y%
- 159 def fnXor(x%,y%)=(x% or y%)-(x% and y%)
- 160 def fnMaskL(k%)=(k%<1)*0+(k%>31)*-1+(((k%<1)+(k%>31))=0)*fnXor(-1,2^(32-k%)-1)
- 161 def fnMaskR(k%)=(k%<1)*0+(k%>31)*-1+(((k%<1)+(k%>31))=0)*2^k%-1
- 162 def fnBit(k%)=((k%<0)+(k%>31))*0+(k%=31)*-1+(((k%<0)+(k%>=31))=0)*2^k%
- 164 'mathTest
- 165 print "fnXor",364,fnXor(5, 361),hex$(fnXor(5, 361))
- 166 print "fnMaskL","FF000000",fnMaskL(8),hex$(fnMaskL(8))
- 167 k% = 8 : gosub 184 : print "MaskL","FF000000",MaskL%,hex$(MaskL%)
- 168 print "fnMaskR","FF",fnMaskR(8),hex$(fnMaskR(8))
- 169 k% = 8 : gosub 189 : print "MaskR","FF",MaskR%,hex$(MaskR%)
- 170 print "fnBit","80",fnBit(7),hex$(fnBit(7))
- 171 k% = 7 : gosub 194 : print "Bit","80",Bit%,hex$(Bit%)
- 172 print "fnShiftL",-256,fnShiftL(-1, 8),hex$(fnShiftL(-1, 8))
- 173 n% = -1 : k% = 8 : gosub 199 : print "ShiftL",-256,ShiftL%,hex$(ShiftL%)
- 174 n% = 42 : k% = 4 : gosub 199 : print "ShiftL",672,ShiftL%,hex$(ShiftL%)
- 175 n% = 16 : k% = 0 : gosub 199 : print "ShiftL",16,ShiftL%,hex$(ShiftL%)
- 176 print "fnShiftR",-1,fnShiftR(-1, 8),hex$(fnShiftR(-1, 8))
- 177 n% = -1 : k% = 8 : gosub 207 : print "ShiftR",-1,ShiftR%,hex$(ShiftR%)
- 178 n% = 42 : k% = 4 : gosub 207 : print "ShiftR",2,ShiftR%,hex$(ShiftR%)
- 179 n% = -999 : k% = 2 : gosub 207 : print "ShiftR",-250,ShiftR%,hex$(ShiftR%)
- 180 end
- 181 'maxTest
- 182 print fnMax(3, 3) : print fnMax(1, 3) : print fnMax(-1, -3)
- 183 return
- 184 'MaskL
- 185 if k% < 1 then MaskL% = 0 : return
- 186 if k% > 31 then MaskL% = -1 : return
- 187 MaskL% = fnXor(-1, (2 ^ (32 - k%) - 1))
- 188 return
- 189 'MaskR
- 190 if k% < 1 then MaskR% = 0 : return
- 191 if k% > 31 then MaskR% = -1 : return
- 192 MaskR% = 2 ^ k% - 1
- 193 return
- 194 'Bit
- 195 if k% < 0 or k% > 31 then Bit% = 0 : return
- 196 if k% = 31 then Bit% = fnMaskL(1) : return
- 197 Bit% = 2 ^ k%
- 198 return
- 199 'ShiftL
- 200 if k% = 0 then ShiftL% = n% : return
- 201 if k% > 31 then ShiftL% = 0 : return
- 202 if k% < 0 then k% = k% * -1 : gosub 207 : ShiftL% = ShiftR% : return
- 203 'ShiftL% = (n% and fnMaskR(31 - k%)) * 2 ^ k%
- 204 ShiftL% = n% * 2 ^ k%
- 205 'if (n% and fnBit(31 - k%)) <> 0 then ShiftL% = (ShiftL% or fnMaskL(1))
- 206 return
- 207 'ShiftR
- 208 if k% = 0 then ShiftR% = n% : return
- 209 if k% > 31 then ShiftR% = 0 : return
- 210 if k% < 0 then k% = k% * -1 : gosub 199 : ShiftR% = ShiftL% : return
- 211 'ShiftR% = (n% and fnMaskR(31)) / 2 ^ k%
- 212 ShiftR% = n% / 2 ^ k%
- 213 'if (n% and fnMaskL(1)) <> 0 then ShiftR% = (ShiftR% or fnBit(31 - k%))
- 214 return
- 215 '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement