Hey everybody, I was just wondering if VEXcode Pro has a prebuilt function to recall the sign of a variable. If not, does anybody know know of a way to build one? The variables I am dealing with are double variables.

There isn’t a sign function built into C++ afaik, but you can make a simple one like this:

```
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}
```

2 Likes

A pretty simple way to make one yourself would be to have a function with a parameter x, and returns the sign like so:

```
if (x > 0) return 1;
if (x < 0) return -1;
return 0;
```

5 Likes

```
x / abs(x);
```

As long as x != 0, this should work.

1 Like

and for the old C programmers amongst us.

```
#define SIGN(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))
```

7 Likes