Skip to main content

value.go

value.go - Overview

  1. Overview This file defines constants for representing NaN (Not a Number) values, including a normal NaN and a stale NaN, and provides utility functions for working with float64 values and pointers.

  2. Detailed Documentation

Constants

  • NormalNaN

    • Purpose: Represents a quiet NaN (Not a Number) value. This is the same as math.NaN().
    • Value: 0x7ff8000000000001
  • StaleNaN

    • Purpose: Represents a signalling NaN value, used as a stale marker.
    • Value: 0x7ff0000000000002

Functions

  • IsNaN(v float64) bool

    • Purpose: Checks if a given float64 value is a normal NaN.
    • Parameters:
      • v (float64): The float64 value to check.
    • Returns:
      • bool: Returns true if the value is a normal NaN, false otherwise.
  • IsStaleNaN(v float64) bool

    • Purpose: Checks if a given float64 value is a stale NaN.
    • Parameters:
      • v (float64): The float64 value to check.
    • Returns:
      • bool: Returns true if the value is a stale NaN, false otherwise.
  • Float64(v float64) *float64

    • Purpose: Returns a pointer to the given float64 value.
    • Parameters:
      • v (float64): The float64 value.
    • Returns:
      • *float64: A pointer to the float64 value.
  • Float64Value(v *float64) float64

    • Purpose: Returns the value of the float64 pointed to by the given pointer, or 0 if the pointer is nil.
    • Parameters:
      • v (*float64): A pointer to a float64 value.
    • Returns:
      • float64: The value of the float64 pointed to by v, or 0 if v is nil.
  1. Code Examples
// Example usage of Float64 and Float64Value
const value = 3.14;
const ptr = Float64(value);
const retrievedValue = Float64Value(ptr);
console.log(retrievedValue); // Output: 3.14

const nilPtr = null;
const retrievedValueFromNil = Float64Value(nilPtr);
console.log(retrievedValueFromNil); // Output: 0
//Example Usage of IsNaN and IsStaleNaN
const normalNaN = Math.NaN;
const staleNaNValue = 0x7ff0000000000002;
const staleNaNFloat = Number(new BigUint64Array([BigInt(staleNaNValue)])[0].toString());

console.log(IsNaN(normalNaN)); //Output: true
console.log(IsStaleNaN(staleNaNFloat)); //Output: true

Include in Getting Started: NO