Connection
Base URL, credentials and a reachable server.
HalfJunia helps review how exponent and fraction fields become binary16 values, with exceptional patterns distinguished from ordinary finite numbers.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
from math import copysign, ldexp
def binary16_value(word):
if type(word) is not int or not 0 <= word <= 65535:
raise ValueError("binary16.word")
sign = -1.0 if word & 0x8000 else 1.0
exponent, fraction = (word >> 10) & 31, word & 1023
if exponent == 31:
return copysign(float("nan") if fraction else float("inf"), sign)
value = ldexp(fraction, -24) if exponent == 0 else ldexp(1024+fraction, exponent-25)
return copysign(value, sign)