value.go
value.go - Overview
-
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. -
Detailed Documentation
Constants
-
NormalNaN
- Purpose: Represents a quiet NaN (Not a Number) value. This is the same as
math.NaN()
. - Value:
0x7ff8000000000001
- Purpose: Represents a quiet NaN (Not a Number) value. This is the same as
-
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): Thefloat64
value to check.
- Returns:
bool
: Returnstrue
if the value is a normal NaN,false
otherwise.
- Purpose: Checks if a given
-
IsStaleNaN(v float64) bool
- Purpose: Checks if a given
float64
value is a stale NaN. - Parameters:
v
(float64): Thefloat64
value to check.
- Returns:
bool
: Returnstrue
if the value is a stale NaN,false
otherwise.
- Purpose: Checks if a given
-
Float64(v float64) *float64
- Purpose: Returns a pointer to the given
float64
value. - Parameters:
v
(float64): Thefloat64
value.
- Returns:
*float64
: A pointer to thefloat64
value.
- Purpose: Returns a pointer to the given
-
Float64Value(v *float64) float64
- Purpose: Returns the value of the
float64
pointed to by the given pointer, or 0 if the pointer isnil
. - Parameters:
v
(*float64): A pointer to afloat64
value.
- Returns:
float64
: The value of thefloat64
pointed to byv
, or 0 ifv
isnil
.
- Purpose: Returns the value of the
- 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