NO MOM
I CANT PAUSE.
Scientific Number Tools Documentation
Support
Browse lessons

14. Sum batches of values with SIMD from C++ (optional)

Build this example in your Unreal project and compare the result at each step.

On this page

This exercise is for C++ projects. If you work exclusively in Blueprint, you can stop here: the array nodes in section 8 remain your workflow. This batch API does not appear as an equivalent set of Blueprint nodes.

You will sum five balances with five increments, keeping one result per position. This is not a sum of all elements into one total.

A. Prepare a test Actor

  1. Use Unreal’s wizard to create a C++ class derived from Actor called MiLoteNumeros. Use your game’s module, not the plugin’s module.
  2. In YourModuleName.Build.cs, add "ScientificNumberTools" to the existing private dependencies list. Keep the other project dependencies.
  3. In MiLoteNumeros.cpp, add these includes after the include for its own header:
#include "ScientificNumber.h"
#include "ScientificNumberSIMD.h"
  1. Find AMiLoteNumeros::BeginPlay(). Keep Super::BeginPlay(); and add the following block underneath it, inside the function:
TArray<FScientificNumber> Saldos;
TArray<FScientificNumber> Incrementos;
for (int32 Indice = 1; Indice <= 5; ++Indice)
{
    Saldos.Add(FScientificNumber(Indice * 10.0, 0));
    Incrementos.Add(FScientificNumber(Indice, 0));
}

TArray<FScientificNumber> Resultados;
Resultados.SetNum(Saldos.Num());
FScientificNumberSIMD::BatchAdd(
    Saldos.GetData(), Incrementos.GetData(),
    Resultados.GetData(), Saldos.Num());

for (int32 Indice = 0; Indice < Resultados.Num(); ++Indice)
{
    const FScientificNumber Esperado((Indice + 1) * 11.0, 0);
    const bool Correcto = Resultados[Indice].IsSuccess()
        && Resultados[Indice] == Esperado;
    UE_LOG(LogTemp, Display, TEXT("Lote[%d]: %s"),
        Indice, Correcto ? TEXT("OK") : TEXT("ERROR"));
}
  1. Compile the project using your usual C++ workflow. Place an instance of MiLoteNumeros in the level and press Play. Open Output Log and search for Lote[.

What you should see: five OK lines, from Lote[0] to Lote[4]. The corresponding results are 11, 22, 33, 44, and 55. You can stop at a breakpoint after BatchAdd and inspect Resultados to see its mantissa and exponent.

B. Check what each position represents

Change Indice * 10.0 to Indice * 100.0 and change the expected value from 11.0 to 101.0. Recompile and repeat: the results will be 101, 202, 303, 404, and 505. Each position combines the balance and increment at that same position.

Both inputs and the output must have at least Count elements; this example prepares five. BatchAdd does not return one global bool: check the state of each resulting Scientific Number before using it in the game.

This exercise teaches you to call the API and read its result. Five elements do not demonstrate a performance improvement; the benefit depends on batch size, data, and hardware. Use it when your code already processes sets of numbers, without changing your Blueprint wallet logic.