Monday 18 January 2016

Julia: Represent Big integers


Julia provide BigInt(x) method to create an arbitrary precision integer.
julia> data=BigInt(123456789876543212345678987654321123456)
123456789876543212345678987654321123456

julia> data=data+1
123456789876543212345678987654321123457

julia> data=data+123456
123456789876543212345678987654321246913

julia> typeof(data)
BigInt

Convert string to BigInt
By using parse method a string can be converted to BigInt.

parse(type, str[, base])
Argument
Description
type
Represents the type to convert. Default base is 10.
str
String to convert. If string is not valid number, then error is raised.
base
Base is optional, for integer conversion default to 10.


julia> parse(BigInt,"123456789876543212345678987654321123456")
123456789876543212345678987654321123456

julia> parse(BigInt,"123456789876543212345678987654321123456",16)
6495562832392744988215426867090392857409893462


Convert String literal to BigInt
By using big string literal form, you can convert a string literal to BigInt.
julia> x=big"100123456789876543212345678987654321123456"
100123456789876543212345678987654321123456

julia> typeof(x)
BigInt








Previous                                                 Next                                                 Home

No comments:

Post a Comment