Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Nice! I'm also using RipGrep.Thank you! 06.06.2020, 01:37, "Doug Coleman" :Yes, you can see this using ripgrep: ➜  factor-master git:(master) ✗ cd vm➜  vm git:(master) ✗ rg nano_countos-genunix.cpp30:uint64_t nano_count() {os-windows.hpp       <---70:uint64_t nano_count();os-macosx.mm77:uint64_t nano_count() {vm.cpp31:      last_nano_count(0),os-unix.hpp49:uint64_t nano_count();os-windows.cpp         <147:uint64_t nano_count() {155:  // nano_count calls would show a difference of about 1 second,factor.cpp67:  srand((unsigned int)nano_count());gc.cpp10:      start_time(nano_count()),14:  start_time = nano_count();17:void gc_event::reset_timer() { temp_time = nano_count(); }20:  times[phase] = (cell)(nano_count() - temp_time);26:  total_time = (cell)(nano_count() - start_time);32:    start_time = nano_count();run.cpp12:void factor_vm::primitive_nano_count() {13:  uint64_t nanos = nano_count();14:  if (nanos < last_nano_count) {16:    std::cout << std::hex << last_nano_count;21:  last_nano_count = nanos;primitives.hpp32:      _(minor_gc) _(modify_code_heap) _(nano_count) _(quotation_code)          \vm.hpp140:  uint64_t last_nano_count;176:  void primitive_nano_count();  On Fri, Jun 5, 2020 at 5:14 PM Alexander Ilin  wrote:Does it also return 8 bytes in 32-bit Windows? 06.06.2020, 01:09, "Doug Coleman" :Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() {  struct timespec t;  int ret = clock_gettime(CLOCK_MONOTONIC, );  if (ret != 0)    fatal_error("clock_gettime failed", 0);  return (uint64_t)t.tv_sec * 10 + t.tv_nsec;} On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman  wrote:As long as you can fully round-trip the integer, it doesn't matter how many bytes you use. nano-count dup 4 >be be> = .f nano-count dup 8 >be be> = .t nano-count dup 128 >be be> = .t   ``log2 1 +`` will give you the required number of bits to store an integer. You will want to round up to a power of 8 bits or a power of two bytes. USE: math.bitwisenano-count dup dup log2 1 + bits = On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" :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?Earlier I wrote: 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?___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 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___

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Doug Coleman
Yes, you can see this using ripgrep:

➜  factor-master git:(master) ✗ cd vm
➜  vm git:(master) ✗ rg nano_count
os-genunix.cpp
30:uint64_t nano_count() {

os-windows.hpp   <---
70:uint64_t nano_count();

os-macosx.mm
77:uint64_t nano_count() {

vm.cpp
31:  last_nano_count(0),

os-unix.hpp
49:uint64_t nano_count();

os-windows.cpp <
147:uint64_t nano_count() {
155:  // nano_count calls would show a difference of about 1 second,

factor.cpp
67:  srand((unsigned int)nano_count());

gc.cpp
10:  start_time(nano_count()),
14:  start_time = nano_count();
17:void gc_event::reset_timer() { temp_time = nano_count(); }
20:  times[phase] = (cell)(nano_count() - temp_time);
26:  total_time = (cell)(nano_count() - start_time);
32:start_time = nano_count();

run.cpp
12:void factor_vm::primitive_nano_count() {
13:  uint64_t nanos = nano_count();
14:  if (nanos < last_nano_count) {
16:std::cout << std::hex << last_nano_count;
21:  last_nano_count = nanos;

primitives.hpp
32:  _(minor_gc) _(modify_code_heap) _(nano_count) _(quotation_code)
   \

vm.hpp
140:  uint64_t last_nano_count;
176:  void primitive_nano_count();


On Fri, Jun 5, 2020 at 5:14 PM Alexander Ilin  wrote:

> Does it also return 8 bytes in 32-bit Windows?
>
> 06.06.2020, 01:09, "Doug Coleman" :
>
> Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so
> you need 8 bytes.
>
> In vm/os-genunix.cpp:
>
> uint64_t nano_count() {
>   struct timespec t;
>   int ret = clock_gettime(CLOCK_MONOTONIC, );
>   if (ret != 0)
> fatal_error("clock_gettime failed", 0);
>   return (uint64_t)t.tv_sec * 10 + t.tv_nsec;
> }
>
> On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman 
> wrote:
>
> As long as you can fully round-trip the integer, it doesn't matter how
> many bytes you use.
>
> nano-count dup 4 >be be> = .
> f
>
> nano-count dup 8 >be be> = .
> t
>
> nano-count dup 128 >be be> = .
> t
>
>
>
> ``log2 1 +`` will give you the required number of bits to store an
> integer. You will want to round up to a power of 8 bits or a power of two
> bytes.
>
> USE: math.bitwise
> nano-count dup dup log2 1 + bits =
>
> On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:
>
> Hello again!
>
>  My specific example is the following. I want to put the output of
> `nano-count` into a `byte-array`, which is fed into a hash. The current
> value of `nano-count` is one of the sources of randomness gathered from the
> system and poured into the hash. To convert the integer value into a
> `byte-array` there are `>le` and `>be`, but they require the number of
> bytes as a parameter. The question is, what should I supply for the value
> received from `nano-count`?
>
>  And the bigger question is, given an integer value, is there a way to
> interrogate it about its byte size, i.e. the minimum number of bytes it
> takes to hold the value without truncation and without leading zeroes:
>
>  Value -- MinSize
>  0 -- 1
>  255 -- 1
>  256 -- 2
>  65535 -- 2
>  65536 -- 3
>  etc.
>
>  I would expect such information to be available somewhere without doing
> the power of two calculations in a loop.
>
> 23.03.2020, 05:41, "Doug Coleman" :
>
> 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?
>
>
>
>
> Earlier I wrote:
>
>  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?
>
> ___
> 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 mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
___
Factor-talk mailing list

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Does it also return 8 bytes in 32-bit Windows? 06.06.2020, 01:09, "Doug Coleman" :Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() {  struct timespec t;  int ret = clock_gettime(CLOCK_MONOTONIC, );  if (ret != 0)    fatal_error("clock_gettime failed", 0);  return (uint64_t)t.tv_sec * 10 + t.tv_nsec;} On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman  wrote:As long as you can fully round-trip the integer, it doesn't matter how many bytes you use. nano-count dup 4 >be be> = .f nano-count dup 8 >be be> = .t nano-count dup 128 >be be> = .t   ``log2 1 +`` will give you the required number of bits to store an integer. You will want to round up to a power of 8 bits or a power of two bytes. USE: math.bitwisenano-count dup dup log2 1 + bits = On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" :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?Earlier I wrote: 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?___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] Integer to Bytes

2020-06-05 Thread Doug Coleman
Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so
you need 8 bytes.

In vm/os-genunix.cpp:

uint64_t nano_count() {
  struct timespec t;
  int ret = clock_gettime(CLOCK_MONOTONIC, );
  if (ret != 0)
fatal_error("clock_gettime failed", 0);
  return (uint64_t)t.tv_sec * 10 + t.tv_nsec;
}

On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman  wrote:

> As long as you can fully round-trip the integer, it doesn't matter how
> many bytes you use.
>
> nano-count dup 4 >be be> = .
> f
>
> nano-count dup 8 >be be> = .
> t
>
> nano-count dup 128 >be be> = .
> t
>
>
> ``log2 1 +`` will give you the required number of bits to store an
> integer. You will want to round up to a power of 8 bits or a power of two
> bytes.
>
> USE: math.bitwise
> nano-count dup dup log2 1 + bits =
>
> On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:
>
>> Hello again!
>>
>>  My specific example is the following. I want to put the output of
>> `nano-count` into a `byte-array`, which is fed into a hash. The current
>> value of `nano-count` is one of the sources of randomness gathered from the
>> system and poured into the hash. To convert the integer value into a
>> `byte-array` there are `>le` and `>be`, but they require the number of
>> bytes as a parameter. The question is, what should I supply for the value
>> received from `nano-count`?
>>
>>  And the bigger question is, given an integer value, is there a way to
>> interrogate it about its byte size, i.e. the minimum number of bytes it
>> takes to hold the value without truncation and without leading zeroes:
>>
>>  Value -- MinSize
>>  0 -- 1
>>  255 -- 1
>>  256 -- 2
>>  65535 -- 2
>>  65536 -- 3
>>  etc.
>>
>>  I would expect such information to be available somewhere without doing
>> the power of two calculations in a loop.
>>
>> 23.03.2020, 05:41, "Doug Coleman" :
>>
>> 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?
>>
>>
>>
>>
>> Earlier I wrote:
>>
>>  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?
>>
>> ___
>> 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


Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread John Benediktsson
Log2 is pretty fast. 

We use BSR if available. 

https://c9x.me/x86/html/file_module_x86_id_20.html


> On Jun 5, 2020, at 3:01 PM, Doug Coleman  wrote:
> 
> 
> As long as you can fully round-trip the integer, it doesn't matter how many 
> bytes you use.
> 
> nano-count dup 4 >be be> = .
> f
> 
> nano-count dup 8 >be be> = .
> t
> 
> nano-count dup 128 >be be> = .
> t
> 
> 
> ``log2 1 +`` will give you the required number of bits to store an integer. 
> You will want to round up to a power of 8 bits or a power of two bytes.
> 
> USE: math.bitwise
> nano-count dup dup log2 1 + bits =
> 
>> On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:
>> Hello again!
>>  
>>  My specific example is the following. I want to put the output of 
>> `nano-count` into a `byte-array`, which is fed into a hash. The current 
>> value of `nano-count` is one of the sources of randomness gathered from the 
>> system and poured into the hash. To convert the integer value into a 
>> `byte-array` there are `>le` and `>be`, but they require the number of bytes 
>> as a parameter. The question is, what should I supply for the value received 
>> from `nano-count`?
>>  
>>  And the bigger question is, given an integer value, is there a way to 
>> interrogate it about its byte size, i.e. the minimum number of bytes it 
>> takes to hold the value without truncation and without leading zeroes:
>>  
>>  Value -- MinSize
>>  0 -- 1
>>  255 -- 1
>>  256 -- 2
>>  65535 -- 2
>>  65536 -- 3
>>  etc.
>>  
>>  I would expect such information to be available somewhere without doing the 
>> power of two calculations in a loop.
>>  
>> 23.03.2020, 05:41, "Doug Coleman" :
>> 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? 
>>  
>>  
>>  
>> Earlier I wrote:
>>  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?
>> ___
>> 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 mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Doug Coleman
As long as you can fully round-trip the integer, it doesn't matter how many
bytes you use.

nano-count dup 4 >be be> = .
f

nano-count dup 8 >be be> = .
t

nano-count dup 128 >be be> = .
t


``log2 1 +`` will give you the required number of bits to store an integer.
You will want to round up to a power of 8 bits or a power of two bytes.

USE: math.bitwise
nano-count dup dup log2 1 + bits =

On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin  wrote:

> Hello again!
>
>  My specific example is the following. I want to put the output of
> `nano-count` into a `byte-array`, which is fed into a hash. The current
> value of `nano-count` is one of the sources of randomness gathered from the
> system and poured into the hash. To convert the integer value into a
> `byte-array` there are `>le` and `>be`, but they require the number of
> bytes as a parameter. The question is, what should I supply for the value
> received from `nano-count`?
>
>  And the bigger question is, given an integer value, is there a way to
> interrogate it about its byte size, i.e. the minimum number of bytes it
> takes to hold the value without truncation and without leading zeroes:
>
>  Value -- MinSize
>  0 -- 1
>  255 -- 1
>  256 -- 2
>  65535 -- 2
>  65536 -- 3
>  etc.
>
>  I would expect such information to be available somewhere without doing
> the power of two calculations in a loop.
>
> 23.03.2020, 05:41, "Doug Coleman" :
>
> 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?
>
>
>
>
> Earlier I wrote:
>
>  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?
>
> ___
> 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


Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" :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?Earlier I wrote: 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?___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Integer to Bytes

2020-03-22 Thread Doug Coleman
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

2020-03-22 Thread Alexander Ilin
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 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 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