.in +8
Compare two strings. Returns the same as the corresponding C functions.
.in
+
+.RI "12) " vector " normalize (" vector ") = " "#12" ;
+.in +8
+Normalize a vector so its length is 1.
+.in
+
+.RI "13) " float " sqrt (" float ") = " "#13" ;
+.in +8
+Get a value's square root.
+.in
.SH BUGS
Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
or see <http://graphitemaster.github.com/gmqcc> on how to contact us.
return 0;
}
+static int qc_sqrt(qc_program *prog)
+{
+ qcany *num, out;
+ CheckArgs(1);
+ num = GetArg(0);
+ out._float = sqrt(num->_float);
+ Return(out);
+ return 0;
+}
+
static int qc_vlen(qc_program *prog)
{
qcany *vec, len;
return 0;
}
+static int qc_normalize(qc_program *prog)
+{
+ double len;
+ qcany *vec;
+ qcany out;
+ CheckArgs(1);
+ vec = GetArg(0);
+ len = sqrt(vec->vector[0] * vec->vector[0] +
+ vec->vector[1] * vec->vector[1] +
+ vec->vector[2] * vec->vector[2]);
+ if (len)
+ len = 1.0 / len;
+ else
+ len = 0;
+ out.vector[0] = len * vec->vector[0];
+ out.vector[1] = len * vec->vector[1];
+ out.vector[2] = len * vec->vector[2];
+ Return(out);
+ return 0;
+}
+
static int qc_strcat(qc_program *prog)
{
char *buffer;
static prog_builtin qc_builtins[] = {
NULL,
- &qc_print, /* 1 */
- &qc_ftos, /* 2 */
- &qc_spawn, /* 3 */
- &qc_kill, /* 4 */
- &qc_vtos, /* 5 */
- &qc_error, /* 6 */
- &qc_vlen, /* 7 */
- &qc_etos, /* 8 */
- &qc_stof, /* 9 */
- &qc_strcat, /* 10 */
- &qc_strcmp /* 11 */
+ &qc_print, /* 1 */
+ &qc_ftos, /* 2 */
+ &qc_spawn, /* 3 */
+ &qc_kill, /* 4 */
+ &qc_vtos, /* 5 */
+ &qc_error, /* 6 */
+ &qc_vlen, /* 7 */
+ &qc_etos, /* 8 */
+ &qc_stof, /* 9 */
+ &qc_strcat, /* 10 */
+ &qc_strcmp, /* 11 */
+ &qc_normalize, /* 12 */
+ &qc_sqrt /* 13 */
};
static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);