Skip to content

normalize and vlen are slightly inconsistent. #244

Open
@divVerent

Description

@divVerent

In FTEQW, looking at the implementations of PF_normalize and PF_vlen, it seems like the following property is true:

normalize(v) == v * (1.0 / vlen(v))

using the MUL_VF and DIV_F instructions.

Non compiler specific test case:

normalize(v) * '1 0 0' == v_x * (1.0 / vlen(v))

In DarkPlaces, this is not entirely true as the intermediate value f, storing vlen(v), is taken the reciprocal of while a double, not while a float (the square root is computed as a double in both engines for both builtins).

I suggest changing https://github.com/DarkPlacesEngine/DarkPlaces/blob/master/prvm_cmds.c#L528 from double f to prvm_vec_t f, so the two functions become consistent with each other, and to document this relationship in a comment. Also, possibly the 1.0 used for computing the reciprocal also needs to be cast to (prvm_vec_t).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions