How to: take a value and raise to the power of another value?

Can anyone provide me a hint?

Here’s my formula that I’m trying to get to work:

def numerator = (6.112 * 2.71828 ^ ((17.67 * device.currentValue(‘temperature’)) / (device.currentValue(‘temperature’) + 243.5)) * device.currentValue(‘humidity’) * 2.1674)

and here’s the error generated:

java.lang.UnsupportedOperationException: Cannot use xor() on this number type: java.math.BigDecimal with value…

I’m definitely not versed enough in java/groovy enough to know what I’m missing or how to do this correctly, so is there anyone out there that can give me a pointer or two?

Don’t have any references in front of me right now, but the ‘^’ character is the XOR. Exponential functions are usually a library function – and I assume Groovy follows that model…

2 Likes

Thanks for that hint. I needed the Math function. Now I’m making progress, thanks again!

2 Likes

If I did it right, here’s how it should look: (I got no errors at least)

def numerator = (6.112 * Math.exp((17.67 * device.currentValue(‘temperature’)) / (device.currentValue(‘temperature’) + 243.5)) * device.currentValue(‘humidity’) * 2.1674)

Thanks for your help @Barkis!

1 Like