Today we’ll begin exploring the C++ Standard Library. As C++ is mostly a superset of C, the C++ Standard Library is mostly a superset of the C Standard Library. So we’ll begin there!

## Posts Tagged math

A reader recently asked what the fastest way to take an absolute value was. It occurred to me that there are a *lot* of ways to do this in Unity! So today we’ll try them all out and see which is best.

The Unity.Mathematics package documentation has a curious statement: “Note that currently, for an optimal usage of this library, it is recommended to use SIMD 4 wide types (float4, int4, bool4…)” Today we’ll explore why we should consider using `float4`

, not `float3`

, after years of using `Vector3`

.

Along with Unity 2019.1 and Burst, the Unity.Mathematics package is now out of Preview. It offers alternatives to longstanding core types in Unity such as `Vector3`

, `Matrix4x4`

, and `Quaternion`

. Today we’ll see how switching to these types can improve performance in Burst-compiled jobs.

IL2CPP can really slow our code down sometimes, and not just for esoteric features. Calling common math and string functions can be dramatically slower in IL2CPP. Today’s article shows you how you can work around this to speed them back up.

`Math.abs`

is a commonly-used utility function for taking the absolute value of a `Number`

. However, there’s no special-case version for taking the absolute value of an `int`

. Of course `Math.abs`

will work for `int`

values, but we can do it faster. Read on for a couple of ways.

The site has had *many* articles about improving the performance of your app, but never discussed the basic methodology on which all optimizations should be based. Today’s article will go over a scientific approach to optimizing that makes use of a tool known as a profiler and demonstrate using an AS3 application just why it’s so important to usage such a tool.

The `Vector3D`

class debuted in Flash Player 10.0 as Adobe’s official implementation of, well, a 3D mathematical vector (not the pseudo-`Array`

class `Vector`

). Weirdly, it has a `w`

component and is therefore technically a 4D vector, but its API inconsistently make use of the fourth dimension. There are also strange oversights, inefficiencies, and functionality it really should have always had. Read on for my custom `Vector3D`

derivative—`Vector3DExt`

—that fixes all of these problems by extending and improving on the original.

I’ve been looking at a lot of AVM2 bytecode recently with the excellent Nemo440 AIR app. Some of the code was using my inline Math.ceil() function and I noticed that the int() cast is implemented like any other function call. Today’s article will show you how to optimize the inline Math.ceil() call even further by avoiding this function call.

As a followup to my article on Inlining Math.ceil(), I decided to inline some more functions in the `Math` class. Read on for the code as well as tests proving correctness and speed.