Code: Select all
@micropython.viper
def foo(v):
return (v*2, v*3)
ViperTypeError: can't do binary op between 'object' and 'int'
Code: Select all
@micropython.viper
def foo(v):
return (v*2, v*3)
Code: Select all
@micropython.viper
def foo(v:int):
return (v*2, v*3)
Code: Select all
@micropython.viper
def foo(v:int):
return (v*3.6, v*2.3)
Code: Select all
@micropython.viper
def foo(v:int):
a = int(v*3.6)
b = int(v*2.3)
return (a, b)
Code: Select all
from array import array
@micropython.asm_thumb
def calc(r0, r1):
vldr(s0, [r0, 0])
vldr(s1, [r0, 1])
vcvt_f32_s32(s0, s0) # convert 1st arg to float in s0
vcvt_f32_s32(s1, s1) # ditto 2nd arg in s1
vldr(s2, [r1, 0]) # Coeffs in s2, s3
vldr(s3, [r1, 1])
vmul(s0, s0, s2) # Products in s0, s1
vmul(s1, s1, s3)
vcvt_s32_f32(s0, s0) # Convert to integer
vcvt_s32_f32(s1, s1)
vstr(s0, [r0, 0])
vstr(s1, [r0, 1]) # Put in result array
coeffs = array('f', (3.6, 2.3))
result = array('i', (0,0))
@micropython.viper
def foo(x: int, y: int):
result[0] = x
result[1] = y
calc(result, coeffs)
foo(7, 8)
print(result)
Code: Select all
@micropython.viper
def foo(x, y):
return (x * 1.2 + y, x - 3.4 / y)
print(foo(3, 4.5))
Code: Select all
import math
import sys
L=220
R=170.0/2
K = (R/2*1.7320508075688772)**2
Rh = R/2
Lsq = L * L
def d(x ,y):
yplusK = y+K
Az = math.sqrt(Lsq - (x)**2 - (y-R)**2)
Bz = math.sqrt(Lsq - (x-Rh)**2 - yplusK)
Cz = math.sqrt(Lsq - (x+Rh)**2 - yplusK)
return (Az, Bz, Cz)
Code: Select all
import math
import sys
L=220
R=170.0/2
K = (R/2*1.7320508075688772)**2
Rh = R/2
Lsq = L * L
@micropython.native
def d(x ,y):
yplusK = y+K
Az = math.sqrt(Lsq - (x)**2 - (y-R)**2)
Bz = math.sqrt(Lsq - (x-Rh)**2 - yplusK)
Cz = math.sqrt(Lsq - (x+Rh)**2 - yplusK)
return (Az, Bz, Cz)
Sorry, I can't reproduce this error. Running your above code (with an extra line to call d: print(d(1, 2))) works just fine on unix and pyboard.PappaPeppar wrote:Using @micropython.native like
...
Gives me: NameError: name 'K' is not defined.