Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

Using Math Functions in Ruby Scripts

asked 2015-08-11 14:14:22 -0600

Alec's avatar

updated 2015-11-07 13:47:22 -0600

I am looking to calculate a square root in a measure I'm writing, but the math.sqrt() method does not work. Is there a way to include Ruby's Math module when writing measures or is there another way to use the higher level math functions?

edit retag flag offensive close merge delete

Comments

@Alec I re-tagged your post to include the existing openstudio-measure tag, rather than openstudio-measures

ericringold's avatar ericringold  ( 2015-08-11 14:24:54 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
6

answered 2015-08-11 14:20:59 -0600

I think the issue may be that the Math module needs to be capitalized, try

Math.sqrt(4)

http://ruby-doc.org/core-2.0.0/Math.h...

edit flag offensive delete link more

Comments

It looks like this did it. Thank you.

Alec's avatar Alec  ( 2015-08-11 14:29:43 -0600 )edit
2

answered 2015-08-11 14:19:59 -0600

I'm guessing you would do something like...

require math

...at the top of your measure.

It's also worth a search of your local BCL folder for "math" to see how it's used elsewhere.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2015-08-11 14:14:22 -0600

Seen: 255 times

Last updated: Aug 11 '15