Re: [Factor-talk] Integer to Bytes
For Factor, integers are either fixnum or bignum size. For C, you tell it how many bytes it occupies according to the C header. Generally the sizes are the same across platforms. If they aren't, you might need two different STRUCT: declarations like in basis/unix/stat/linux/32/32.factor and basis/unix/stat/linux/64/64.factor. The main point -- function signatures and struct declarations usually handle the integer sizes and you shouldn't have to think much about it. Do you have a specific example? ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Integer to Bytes
Thank you! One more question. I want to convert an integer into a byte-array containing its bytes. In my use case it was the return value of the nano-count, but the question is general: how can I get the bytes of an integer. For floats there are primitives like float>bits and double>bits, and for integers there is >le and >be, but for the latter two I need to specify the size in bytes. Is there a way to ask an integer how many bytes it occupies? Because from the documentation it's not clear at all how many bytes nano-count would return, and it may vary depending on the current platform. What am I missing? 23.03.2020, 03:13, "Doug Coleman" :You could do this: : SODIUM_SIZE_MAX ( -- x ) cell-bits on-bits ; where cell-bits gives 32/64 and on-bits turns them to ones. On Sun, Mar 22, 2020 at 6:44 PM Alexander Ilinwrote:Hello! I'm creating the sodium library FFI for Factor, and I found the following definition in the Sodium C headers:#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, which represents a maximum value for array sizes and similar memory limits. It'll have the max value of the size_t type, which is either 16-bit, 32-bit or 64-bit depending on the compilation target platform. How should I define the SODIUM_SIZE_MAX constant in Factor?---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk ---=---Александр ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Platform Max Int
You could do this: : SODIUM_SIZE_MAX ( -- x ) cell-bits on-bits ; where cell-bits gives 32/64 and on-bits turns them to ones. On Sun, Mar 22, 2020 at 6:44 PM Alexander Ilin wrote: > Hello! > > I'm creating the sodium library FFI for Factor, and I found the > following definition in the Sodium C headers: > > #define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B)) > #define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) > > I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, > which represents a maximum value for array sizes and similar memory limits. > It'll have the max value of the size_t type, which is either 16-bit, > 32-bit or 64-bit depending on the compilation target platform. > > How should I define the SODIUM_SIZE_MAX constant in Factor? > > ---=--- > Александр > > > > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Platform Max Int
Hello! I'm creating the sodium library FFI for Factor, and I found the following definition in the Sodium C headers: #define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B)) #define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, which represents a maximum value for array sizes and similar memory limits. It'll have the max value of the size_t type, which is either 16-bit, 32-bit or 64-bit depending on the compilation target platform. How should I define the SODIUM_SIZE_MAX constant in Factor? ---=--- Александр ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk