Understanding the result of .dump: low level data for float, hexadecimal for string, gc, fmt, flg and set

Hello,

I would like to know the exact meaning of the text returned by .dump.

  • -1.0.dump returns
    Float -1.000000   00000000 BFF00000
    -> -1.0
    
    • Is the part 00000000 the significant part (mantissa)?
    • Is the part BFF00000 the exponent part with sign bit?
  • "10".dump returns
    Instance of String {    (0x12bcd44a8, gc=98, fmt=07, flg=10, set=02)
    indexed slots [2]
        0 : 1
        1 : 0
    }
    -> 10
    
    • What is its functionality? Is the hexadecimal 0x12bcd44a8 perhaps the address of the physical memory (RAM) that sclang allocates to make the string used to identify the object the same object or not by the === or !== operator?
    • What does gc mean? What is its functionality?
    • What does fmt mean? What is its functionality?
    • What is flg? What is its functionality?
    • What is set? What is its functionality?

Sorry to ask so many questions, but I would really appreciate it if you could share your expertise.

IIRC, a 64-bit float has: 1 sign bit, 11 exponent bits, and 52 mantissa bits (+1 implicit bit for 53 bits precision) – edit: first version wasn’t correct. There’s plenty of documentation online about floating point formats – best to read up on it, rather than guessing.

EDIT: 00000000 is the least-significant word, BFF00000 is the more significant.

1011 1111 1111 0000  0000 0000 0000 0000 , 0000 0000 0000 0000  0000 0000 0000 0000
  • 1 = sign bit (negative)
  • 011 1111 1111 = exponent bits. Decimal value is 1023. The offset (see floating point docs) is 1023, so the actual exponent is 1023 - 1023 = 0.
  • 0’s are mantissa bits. There’s always an implicit 1 before the binary point, so this number is binary 1.00000000… * 2^0, then negated by the sign bit = -1.0.

Yes, a memory location.

The other values aren’t directly useful for normal use. Gc would be garbage-collection status (I don’t know what the specific values are); I guess fmt relates to the type tag belonging to the PyrSlot object in the backend; flg and set, no idea.

hjh

1 Like

It is the “raw” hex representation of the 64 bit double value. You can use a site like https://baseconvert.com/ieee-754-floating-point to explore this. The high and low words appear switched in the printout because of programming error and/or endianness: Endianness - Wikipedia

It is the virtual address (Virtual memory - Wikipedia) of the object. Only the OS kernel knows the physical address. You didn’t see this for the float because certain small types are stored directly as values rather than by reference.

Direct hex printouts of these bytes: supercollider/lang/LangSource/PyrObject.h at develop · supercollider/supercollider · GitHub. they are not well documented and I had to poke around to find what they did the first time I saw them. But you can learn a few things from the comment above the class.

GC: garbage collector flags. I never learned what these do.

fmt: if the object is a raw array (hand waving here), the type of the array slots. String is a raw array with char slots so it gets 0x07 - supercollider/lang/LangSource/PyrObject.h at develop · supercollider/supercollider · GitHub. This is directly related to RawArray and its subclasses - RawArray | SuperCollider 3.12.2 Help

flg: just used for GC and immutability. strings are immutable so they get 0x10 - supercollider/lang/LangSource/PyrObject.h at develop · supercollider/supercollider · GitHub

set: " size class". 0 for most objects, and for raw arrays 2^set gives you the size of the backing memory in slots. So a Int16Array with set value 0x03 would be backed by 2^3 * sizeof(int16_t) = 16 bytes. You can play around with different array sizes to get an intuition for this.

2 Likes