Exemplo n.º 1
0
def real_floating_point_bytes(n, _size, big_endian):
    if isinstance(n, values.W_Flonum):
        v = n.value
    elif isinstance(n, values.W_Fixnum):
        v = float(n.value)
    elif isinstance(n, values.W_Bignum):
        v = rbigint.tofloat(n.value)
    else:
        raise SchemeException("real->floating-point-bytes: expected real")

    size = _size.value
    if size != 4 and size != 8:
        raise SchemeException("real->floating-point-bytes: size not 4 or 8")

    intval = longlong2float.float2longlong(v)

    if big_endian is not values.w_false:
        intval = rarithmetic.byteswap(intval)

    chars  = [chr((intval >> (i * 8)) % 256) for i in range(size)]
    return values.W_Bytes.from_charlist(chars)
Exemplo n.º 2
0
def real_floating_point_bytes(n, _size, big_endian):
    if isinstance(n, values.W_Flonum):
        v = n.value
    elif isinstance(n, values.W_Fixnum):
        v = float(n.value)
    elif isinstance(n, values.W_Bignum):
        v = rbigint.tofloat(n.value)
    else:
        raise SchemeException("real->floating-point-bytes: expected real")

    size = _size.value
    if size != 4 and size != 8:
        raise SchemeException("real->floating-point-bytes: size not 4 or 8")

    intval = longlong2float.float2longlong(v)

    if big_endian is not values.w_false:
        intval = rarithmetic.byteswap(intval)

    chars = [chr((intval >> (i * 8)) % 256) for i in range(size)]
    return values.W_Bytes.from_charlist(chars)
Exemplo n.º 3
0
def to_fl(n):
    if isinstance(n, values.W_Fixnum):
        return values.W_Flonum(float(n.value))
    if isinstance(n, values.W_Bignum):
        return values.W_Flonum(rbigint.tofloat(n.value))
    raise SchemeException("->fl: expected an exact-integer")
Exemplo n.º 4
0
def to_fl(n):
    if isinstance(n, values.W_Fixnum):
        return values.W_Flonum(float(n.value))
    if isinstance(n, values.W_Bignum):
        return values.W_Flonum(rbigint.tofloat(n.value))
    raise SchemeException("->fl: expected an exact-integer")