GPUDevice from init()
number of elements to scale (must be a positive integer)
scalar multiplier
Float64Array input/output vector
stride for x (must be a positive integer)
Scales a double-precision vector by a constant: $$x \leftarrow \alpha x$$
Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
import { init, cleanup } from "wgblas";
import { dscal } from "wgblas/dscal";
import { GpuVector } from "wgblas/classes/GpuVector";
const device = await init();
const n = 5;
const alpha = 3;
const x = new Float64Array([1, 2, 3, 4, 5]);
const xGpu = GpuVector.from(x);
console.log("x: ", x);
await dscal(device, n, alpha, xGpu, 1);
const result = await xGpu.read();
console.log("result:", result);
xGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
number of elements to scale (must be a positive integer)
scalar multiplier
Float64Array-backed GpuVector input/output vector (mutated in place)
stride for x (must be a positive integer)
Scales a double-precision vector by a constant: $$x \leftarrow \alpha x$$
xandalphaare each split into a (hi, lo) double-double f32 pair (seesplitDoubleDouble/f64.mjs) since WGSL has no f64 type; the multiply uses Dekker's double-double algorithm (seeshaders/f64/), giving ~48 bits of mantissa — more than a single f32 (24 bits) but less than true f64 (52 bits), so results are not bit-exact with a CPU double.Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
Browser (standalone HTML):