• Stars
    star
    3
  • Rank 3,847,251 (Top 78 %)
  • Language
    Jupyter Notebook
  • License
    Other
  • Created over 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convenient literal expressions for large numbers

DeepConvert

convenient literal construction of values of large data types

Linux, OSX: Build Status   Windows: Build Status       Coverage Status codecov.io

Most of the following is also in this Jupyter notebook.

This package provides convenient literal construction of values of large data types.

It defines macros that define functions to convert all numbers in an expression to a given numeric type and evaluate that expression. (Like deepcopy, it traverses the entire expression tree.) It is meant to allow a convenient way to input large numbers without overflow.

The macros @bigfloat, @bigint, and @int128 convert numeric literals in their argument to BigFloat, BigInt or Int128. See examples below.

Two examples of non-standard AbstractString literals are exported, bf and bi, which construct BigFloats and BigInts from strings. Note that these are not the same as the string literal big in Julia Base.

julia> BigInt[2^63, 2^64]
2-element Array{BigInt,1}:  # awesome, an array of BigInt's!
 -9223372036854775808
                    0

julia> using DeepConvert
julia> bi"[2^63, 2^64]"
2-element Array{BigInt,1}:
  9223372036854775808
 18446744073709551616

julia> @bigint [2^63, 2^64]
2-element Array{BigInt,1}:
  9223372036854775808
 18446744073709551616
julia> binomial(100, 50)
ERROR: OverflowError: binomial(100, 50) overflows

julia> @int128 binomial(100, 50)
100891344545564193334812497256
julia> round(bf"((1 + 2e-50) - (1 + 1e-50)) / (1e-50)")
1.0

deepbigfloat takes an expression or string as an argument and acts on literals

julia> a = parse("1 + 1")
:(1 + 1)

julia> deepbigfloat(a)
2e+00 with 256 bits of precision

julia> deepbigfloat("1 + 1")
2e+00 with 256 bits of precision

@mkdeepconvert(funcname, convfunc)

Example

Define a function that converts Reals in an expression to Int128

julia> using DeepConvert

julia> Int128(2 * (10^19 + 10^17))  # does not do what you want
1753255926290448384

julia> @mkdeepconvert(convint128, Int128)
convint128 (generic function with 3 methods)

julia> convint128(:( 2 * (10^19 + 10^17) )) # does what you want
20200000000000000000

julia> convint128("2 * (10^19 + 10^17)")  # can use double quotes, as well
20200000000000000000

julia> @mkdeepconvert(convuint64, UInt64)
convuint64 (generic function with 3 methods)

julia> convuint64("10^19 + 10^17")
0x8c2a687ce7720000

bi, bf non-standard AbstractString literals

bi is implemented by

@mkdeepconvert(deepbigint, BigInt)
macro bi_str(s) deepbigint(s) end

@bigint, @int128

Any Int and Int128 values in the expression following @bigint are converted to BigInt. A contrived example:

@bigint function g(x)
           return 2^64 * x
        end

Gives this,

julia> g(2.0)
3.6893488147419103232e+19

To override the macro, you have to ask for the smaller type,

@bigint function g(x)
           return Int(2)^Int(64) * x   # always returns zero
        end

In effect, this temporarily makes BigInt the default integer type.

More Repositories

1

Symata.jl

language for symbolic mathematics
Julia
172
star
2

JuliaQuantumInformation

List of quantum information and computation projects in Julia
52
star
3

ManualDispatch.jl

Avoid method dispatch at runtime
Julia
39
star
4

EmpiricalCDFs.jl

Online empirical cumulative distribution functions
Julia
33
star
5

SymataSyntax.jl

Mathematica syntax for Symata.jl
Julia
13
star
6

julia_project

Manage a Julia project living within a Python package
Python
13
star
7

ZChop.jl

replace small numbers with zero
Julia
13
star
8

qinf

Quantum information library for Maxima
Common Lisp
11
star
9

PrimeSieve.jl

fast generation and counting of primes
Julia
10
star
10

IsApprox.jl

Interface for approximate and exact equality
Julia
10
star
11

StreamToString.jl

redirect stdout and stderr to a string in Julia
Julia
6
star
12

pika-asynchronous-consumer

asynchronous RabbitMQ consumer
Python
6
star
13

FileCmp.jl

Compare two files byte by byte
Julia
6
star
14

PDL-IO-Matlab

Reading and writing matlab format data files for the perl data language.
C
5
star
15

IdentityMatrix.jl

efficient methods for identity matrices
Julia
4
star
16

ranwalk-Julia-vs-Cxx

Compare speed of Julia and C++-11 for random walk simulations
C++
4
star
17

CachePath.jl

Allow caching precompiled Julia code in a specified directory
Julia
3
star
18

Qurt.jl

Qiskit compatible circuit manipulation in Julia
Julia
3
star
19

PDL-DSP-Windows

Signal processing window functions for PDL
Perl
3
star
20

PDL-Fit-Levmar

PDL interface to constrained Levenberg-Marquardt library levmar
C
3
star
21

openqasm-rust

QASM 3.0 parser for the Rust langauge
Rust
3
star
22

MaximumLikelihoodPower.jl

Maximum Likelihood Estimate for power laws
Julia
3
star
23

BlockEnums.jl

Like Enums but with more features
Julia
3
star
24

VoronoiCells.jl

Work with Voroni cells of a point process
Julia
3
star
25

DictTools.jl

Improvements on standard dict tools in julia
Julia
2
star
26

mixima

Compatibility tools for porting from Mathematica to Maxima
Common Lisp
2
star
27

SocialNet.jl

Simplified Social Network
Julia
2
star
28

MethodInSrc.jl

Test whether a call is dispatched to a method in your module
Julia
2
star
29

PermPlain.jl

Permutations of integers
Julia
2
star
30

gjlcxx_util

c++ templates for physics simulations and sundry
C++
2
star
31

diffeq_julia

alternative packaging of diffeqpy
Python
2
star
32

mext

Package management and packages for Maxima (the CAS)
Common Lisp
2
star
33

QuantumGlue.jl

Convert types between quantum packages
Julia
1
star
34

TupleArrays.jl

a lot like StructArrays
Julia
1
star
35

SampleShots.jl

experiments with shot sampling
Julia
1
star
36

PDL-StatPhys-Cluster

cluster counting routine for statistical physics (biology,...) 2-d site model
Perl
1
star
37

RowTables.jl

Data table with row-wise storage
Julia
1
star
38

hexdens

create density plots on a triangular or square lattice
Perl
1
star
39

vigenere-crack

program to encode decode decrypt vigenere cipher
Perl
1
star
40

clevo-xsm-wmi

Kernel module for keyboard backlighting of Clevo SM series notebooks. (And several EM/ZM/DM series models)
C
1
star
41

BitsX.jl

bit manipulation and static bit vectors
Julia
1
star
42

Rotate.jl

Cyclic assignment
Julia
1
star
43

ControlFlow.jl

Some constructs for control flow
Julia
1
star
44

msieve-shared

shared library version of msieve
C
1
star
45

PDL-DSP-Iir

Infinite impulse response and recursive filters
Perl
1
star
46

prime-pi-maxima

prime counting function for maxima, the CAS
Common Lisp
1
star
47

CBOOCall.jl

The way of CBOO for Julia
Julia
1
star
48

GraphsExt.jl

Some types and functions that could be in Graphs.jl
Julia
1
star