VEX constants for type limits and common math values

   3157   3   1
User Avatar
Member
29 posts
Joined: May 2018
Offline
Are there any named constants built into VEX for type limits (min/max float/int) and common math values (pi, e)?
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Take a look at $HFS/houdini/vex/include/math.h" You can include math.h in vex like this:
#include <math.h>
Then those definitions will be available in your code.
f@debug = M_TOLERANCE
etc.
You can also make you own definitions and include them when needed. Make a file “mystuff.h” and use #define to set your own constants like this
#define VERYSMALLNUMBER 0.00000000000000001
, and place the file in YOURPREFSDIR/vex/include/mystuff.h.
To use it in vex put #include <mystuff.h> in your vex code.

-b
Edited by bonsak - March 30, 2019 05:38:03
http://www.racecar.no [www.racecar.no]
User Avatar
Member
29 posts
Joined: May 2018
Offline
bonsak
include math.h in vex like this

Perfect! I didn't realize you could include files in VEX because I was only reading the VEX language reference [www.sidefx.com]. The documentation on includes is in the VCC compiler reference [www.sidefx.com].

In addition two the two include locations you mentioned ($HFS and YOURPREFSDIR), you can also place files in $JOB/vex/include.

I also noticed that I was able to use the defines from math.h without having to include it in my VEXpression in the Attribute Wrangler. I dove into the Attribute Wrangle node, and then right clicked on the Attribute VOP inside and selected VEX/VOP Options > View VEX Code and discovered math.h is already included. Here's the boilerplate:

//
// VEX Code Generated by Houdini 17.5.173
// Date: Sun Mar 31 12:48:29 2019
// File: E:/code/HoudiniExamples/vex
// Node: /obj/geo1/attribwrangle1/attribvop1
//

#ifndef VOP_OP
#define VOP_OP
#endif
#ifndef VOP_CVEX
#define VOP_CVEX
#endif

#pragma opname attribvop1
#pragma oplabel "Local Vop Code"
#pragma opmininputs 1
#pragma opmaxinputs 1


#include <math.h>
void
_obj_geo1_attribwrangle1_attribvop1_snippet1()
{
    // The VEXpression parameter from the Attribute Wrangle node is inserted here!
    
}

cvex
obj_geo1_attribwrangle1_attribvop1()
{
    
    // Code produced by: snippet1
    _obj_geo1_attribwrangle1_attribvop1_snippet1();
}
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Cool! Didnt know math.h was included by default. Good to know.

-b
http://www.racecar.no [www.racecar.no]
  • Quick Links