Bill Allombert on Wed, 29 Jan 2025 14:42:21 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: 2^[1,3]


On Wed, Jan 29, 2025 at 02:28:46PM +0100, Ruud H.G. van Tol wrote:
> 
> ? 2^[1,3]
> % [2.0000000000000000000000000000000000000,
> 8.0000000000000000000000000000000000000]
> 
> ? vecsum(2^[1,3])
> % 10.000000000000000000000000000000000000

Use fromdigits:
? fromdigits([1,3],2)
% = 10

> I wonder why 2^[1,3] uses reals.

This is a trap: the vector rule only apply to floating-points operations.

> How to best convert something like (int) 6131786 to (int) 2^1 + 2^3 + 2^6 +
> 2^7 + 2^8?

You can use the binary() function.

Cheers,
Bill.