[Scilab-users] overloading concat "[ ]" operators
Pierre Vuillemin
contact at pierre-vuillemin.fr
Fri Jul 1 11:17:46 CEST 2016
Hi Philippe,
You can create another object, a matrix of bing int that stacks your
bigint in a list, i.e.
x = tlist(["bigint","rep","signe"],[7654321;5678998;1234],1)
y = tlist(["bigint","rep","signe"],[3456789;5432112;9876],1)
X = tlist(["mbigint","entries"],list(x,y))
Then you can overload the display for "mbigint" for instance with
function %mbigint_p(e)
str = ""
for i = 1:length(e.entries)
for j =length(e.entries(i).rep):-1:1
str = sprintf("%s%d",str,e.entries(i).rep(j))
end
str = str +"\n"
end
printf(str)
endfunction
If you want to make matrix (not only vectors), then you need to add the
size of the matrix as an attribute of "mbigint" and reshape the display
accordingly.
Pierre.
Le 01.07.2016 10:41, philippe a écrit :
> Hi,
>
> I have created a simple data structure to handle "big integers" . It
> is
> based on scilab tlist and named "bigint" . I have overloaded basic
> unary/binary operators for bigint (like +,*,-,/,^,==,<,>,... ) :
>
>
>
> -->x=bigint('123456789987654321')
> x =
>
>
> 123456789987654321
>
> -->y=bigint('987654321123456789')
> y =
>
>
> 987654321123456789
>
> -->z=x-y
> z =
>
>
> -864197531135802468
>
>
>
> but now I want to create matrix of bigint so I need to create
> functions like %bigint_c_bigint and %bigint_f_bigint . I try using
> "cell" It's not exactly what I was expecting : matrix entries are
> displayed as tlist instead of bigint display (modified via %bigint_p )
>
>
>
> -->T=cell()
> T =
>
>
> []
>
>
>
> -->T(1).entries=x
> T =
>
>
> tlist(["bigint","rep","signe"],[7654321;5678998;1234],1)
>
> -->T(2).entries=y
> T =
>
>
> !tlist(["bigint","rep","signe"],[7654321;5678998;1234],1) !
> ! !
> !tlist(["bigint","rep","signe"],[3456789;5432112;9876],1) !
>
>
> -->T(3).entries=z
> T =
>
>
> !tlist(["bigint","rep","signe"],[7654321;5678998;1234],1) !
> ! !
> !tlist(["bigint","rep","signe"],[3456789;5432112;9876],1) !
> ! !
> !tlist(["bigint","rep","signe"],[5802468;9753113;8641],-1) !
>
>
>
> how could I get a display like
>
>
> -->T
> T =
>
>
> ! 123456789987654321 !
> ! !
> ! 987654321123456789 !
> ! !
> ! -864197531135802468 !
>
>
>
> actually I only get
>
> -->T.entries
> ans =
>
>
> ans(1)
>
>
> 123456789987654321
>
> ans(2)
>
>
> 987654321123456789
>
> ans(3)
>
>
> -864197531135802468
>
>
>
> Philippe
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
More information about the users
mailing list