---
source: boltffi_bindgen/src/render/typescript/templates.rs
expression: template.render().unwrap()
---
const _MathUtilsFinalizer: FinalizationRegistry<number> | null =
  typeof FinalizationRegistry === "undefined"
    ? null
    : new FinalizationRegistry<number>((handle) => {
        (_exports.boltffi_math_utils_free as Function)(handle);
      });

export class MathUtils {
  private _handle: number;
  private _disposed: boolean;

  private constructor(handle: number) {
    this._handle = handle;
    this._disposed = false;
    _MathUtilsFinalizer?.register(this, handle, this);
  }

  static _fromHandle(handle: number): MathUtils {
    if (handle === 0) {
      throw new Error("MathUtils received a null handle");
    }
    return new MathUtils(handle);
  }

  [Symbol.dispose](): void {
    this.dispose();
  }

  dispose(): void {
    if (this._disposed) {
      return;
    }
    this._disposed = true;
    _MathUtilsFinalizer?.unregister(this);
    (_exports.boltffi_math_utils_free as Function)(this._handle);
    this._handle = 0;
  }

  private _assertNotDisposed(): void {
    if (this._disposed) {
      throw new Error("MathUtils has been disposed");
    }
  }

  static add(a: number, b: number): number {
    return (_exports.boltffi_math_utils_add as Function)(a, b);
  }
}
