Bill Allombert on Mon, 03 Oct 2022 21:27:48 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Vectors and integer exponentiation |
On Mon, Oct 03, 2022 at 11:52:29AM +0200, Martin Becker wrote: > Hello, > > In GP (tested with versions 2.15.0 and 2.13.1), the expression > > 2^[4,6,8] > > evaluates to a vector of floating point numbers, while > > [2^n|n<-[4,6,8]] > > evaluates to a vector of integers. > > I would have expected integers in the first case, too, > or perhaps a type error if exponentiation was not meant to > auto-unbox vectors. Is this a bug? No, this is the consequence of historical design before [<-|] was introduced that allows transcendental functions to act component-wise on vectors: ? exp([1,2,3]) %6 = [2.7182818284590452353602874713526624978,7.3890560989306502272304274605750078132,20.085536923187667740928529654581717897] and it happens that 2^[4,6,8] do the same thing as exp(log(2)*[4,6,8]) Cheers, Bill