Skip to content

Commit

Permalink
Merge pull request #1878 from arturo-lang/upgrade-nim-to-2.2.2
Browse files Browse the repository at this point in the history
Upgrade to Nim 2.2.2
  • Loading branch information
drkameleon authored Feb 8, 2025
2 parents a285640 + f7aa997 commit e57e8df
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 101 deletions.
2 changes: 1 addition & 1 deletion examples/rosetta/arithmetic - complex.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
a: 1.0+1.0i
b: 3.141592653589793+1.2i
a + b: 4.141592653589793+2.2i
a * b: 1.941592653589793+4.341592653589793i
a * b: 1.9415926535897932+4.341592653589793i
1 / a: 0.5-0.5i
neg a: -1.0-1.0i
conj a: 1.0-1.0i
2 changes: 1 addition & 1 deletion examples/rosetta/averages - root mean square.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.204836822995428
6.2048368229954285
10 changes: 5 additions & 5 deletions examples/rosetta/benford's law.res
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
digit actual expected
1 0.301 0.3010299956639811
2 0.177 0.1760912590556812
1 0.301 0.30102999566398114
2 0.177 0.17609125905568124
3 0.125 0.1249387366082999
4 0.095 0.09691001300805641
4 0.095 0.0969100130080564
5 0.08 0.0791812460476248
6 0.067 0.06694678963061322
7 0.056 0.05799194697768673
8 0.053 0.05115252244738128
7 0.056 0.057991946977686726
8 0.053 0.051152522447381284
9 0.045 0.04575749056067514
2 changes: 1 addition & 1 deletion examples/rosetta/calculating the value of e.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.718281828459046
2.7182818284590455
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Through points:
(x: 0.1234, y: 0.9876)
(x: 0.8764999999999999, y: 0.2345)
(x: 0.8765, y: 0.2345)
and radius 2.0, you can construct the following circles:
(x: 1.863111801658189, y: 1.974211801658189, r: 2.0)
(x: 1.8631118016581893, y: 1.974211801658189, r: 2.0)
(x: -0.8632118016581896, y: -0.7521118016581892, r: 2.0)

Through points:
Expand All @@ -20,7 +20,7 @@ and radius 2.0, you can construct the following circles:

Through points:
(x: 0.1234, y: 0.9876)
(x: 0.8764999999999999, y: 0.2345)
(x: 0.8765, y: 0.2345)
and radius 0.5, you can construct the following circles:
ERROR: separation of points > diameter

Expand Down
4 changes: 2 additions & 2 deletions examples/rosetta/continued fraction.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1.414213562373095
2.718281828459046
3.141592653589544
2.7182818284590464
3.1415926535895435
2 changes: 1 addition & 1 deletion examples/rosetta/entropy.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.846439344671015
1.8464393446710154
4 changes: 2 additions & 2 deletions examples/rosetta/fivenum.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[36.0 40.0 7.0 39.0 41.0 15.0] ->
[7.0 15.0 37.5 40.0 41.0]

[0.14082834 0.0974879 1.73131507 0.87636009 -1.95059594 0.7343855500000001 -0.03035726 1.4667597 -0.74621349 -0.72588772 0.6390516000000001 0.61501527 -0.9898378 -1.00447874 -0.62759469 0.66206163 1.04312009 -0.10305385 0.75775634 0.32566578] ->
[-1.95059594 -0.676741205 0.23324706 0.746070945 1.73131507]
[0.14082834 0.0974879 1.73131507 0.87636009 -1.95059594 0.73438555 -0.03035726 1.4667597 -0.74621349 -0.72588772 0.6390516 0.61501527 -0.9898378 -1.00447874 -0.62759469 0.66206163 1.04312009 -0.10305385 0.75775634 0.32566578] ->
[-1.95059594 -0.676741205 0.23324706 0.746070945 1.73131507]
2 changes: 1 addition & 1 deletion examples/rosetta/haversine formula.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2887.259950607111
2887.2599506071106
2 changes: 1 addition & 1 deletion examples/rosetta/kahan summation.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sum of 1.0, epsilon and -epsilon for epsilon: 1.110223024625157e-16
Sum of 1.0, epsilon and -epsilon for epsilon: 1.1102230246251565e-16
Is result equal to 1.0?
- simple addition: false
- using Kahan sum: true
2 changes: 1 addition & 1 deletion examples/rosetta/nth root.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2.024397458499885
1.453198460282268
1.4531984602822678
2.23606797749979
2 changes: 1 addition & 1 deletion examples/rosetta/perlin noise.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1369199587840001
0.13691995878400012
2 changes: 1 addition & 1 deletion examples/rosetta/problem of apollonius.res
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.0 2.1 3.9
2.0 0.8333333333333333 1.166666666666667
2.0 0.8333333333333333 1.1666666666666667
4 changes: 2 additions & 2 deletions examples/rosetta/real constants and functions.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Euler: 2.718281828459045
Pi: 3.141592653589793
sqrt 2.0: 1.414213562373095
sqrt 2.0: 1.4142135623730951
ln 100: 4.605170185988092
log(10) 100: 2.0
exp 3: 20.08553692318767
exp 3: 20.085536923187668
abs -1: 1
floor 23.536: 23
ceil 23.536: 24
Expand Down
2 changes: 1 addition & 1 deletion examples/rosetta/sum of a series.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.643934566681561
1.6439345666815615
2 changes: 1 addition & 1 deletion examples/rosetta/temperature conversion.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[celcius:-173.15 fahrenheit:-279.67 rankine:180.0]
[celcius:-173.14999999999998 fahrenheit:-279.67 rankine:180.0]
13 changes: 5 additions & 8 deletions src/extras/gmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,11 @@ func mpz_xor*(a2: var mpz_t; a3: mpz_t; a4: mpz_t) {.importc.}
{.pop.}

#=======================================
# Methods
# Destructors
#=======================================

func finalizeInt*(z: ref mpz_t) =
mpz_clear(z[])
proc `=destroy`*(x: mm_mpz_struct) =
mpz_clear(addr x)

# func finalizeFloat*(z: ref mpf_t) =
# mpf_clear(z[])

func finalizeRat*(z: ref mpq_t) =
mpq_clear(z[])
proc `=destroy`*(x: mm_mpq_struct) =
mpq_clear(addr x)
8 changes: 5 additions & 3 deletions src/extras/mpfr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type

type
mpfr* = mm_mpfr_struct
mpfr_ptr* = ptr mm_mpfr_struct

#=======================================
# Constants
Expand All @@ -59,6 +60,7 @@ const

func mpfr_get_version*(): cstring {.importc.}

func mpfr_clear*(a: mpfr_ptr) {.importc.}
func mpfr_clear*(a: var mpfr) {.importc.}
func mpfr_init*(a: var mpfr) {.importc.}
func mpfr_set*(a: var mpfr, b: mpfr, c: mpfr_rnd_t) {.importc.}
Expand Down Expand Up @@ -96,8 +98,8 @@ func mpfr_pow_z*(a: var mpfr, b: mpfr, c: mpz_t, d: mpfr_rnd_t) {.importc.}
{.pop.}

#=======================================
# Methods
# Destructors
#=======================================

func finalizeFloat*(z: ref mpfr) =
mpfr_clear(z[])
proc `=destroy`*(x: mm_mpfr_struct) =
mpfr_clear(addr x)
46 changes: 23 additions & 23 deletions src/helpers/bignums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func newInt*(x: culong): Int =
# Warning: A custom '=destroy' hook which takes a 'var T' parameter is deprecated; it should take a 'T' parameter [Deprecated]
# ```
# labels: 3rd-party, enhancement
new(result, finalizeInt)
result = Int()
mpz_init_set_ui(result[], x)

func newInt*(x: int = 0): Int =
new(result, finalizeInt)
result = Int()
when isLLP64():
if x.fitsLLP64Long:
mpz_init_set_si(result[], x.clong)
Expand All @@ -110,57 +110,57 @@ func newInt*(x: int = 0): Int =
mpz_init_set_si(result[], x.clong)

func newInt*(x: Float): Int =
new(result,finalizeInt)
result = Int()
mpz_init(result[])
mpz_set_d(result[], mpfr_get_d(x[], MPFR_RNDN))

func newInt*(s: string, base: cint = 10): Int =
validBase(base)
new(result, finalizeInt)
result = Int()
if mpz_init_set_str(result[], s, base) == -1:
raise newException(ValueError, "String not in correct base")

func newFloat*(x: float): Float =
new(result, finalizeFloat)
result = Float()
mpfr_init(result[])
mpfr_set_d(result[], x, MPFR_RNDN)

func newFloat*(x: culong): Float =
new(result, finalizeFloat)
result = Float()
mpfr_init(result[])
mpfr_set_ui(result[], x, MPFR_RNDN)

func newFloat*(x: int = 0): Float =
new(result, finalizeFloat)
result = Float()
mpfr_init(result[])
mpfr_set_si(result[], x.clong, MPFR_RNDN)

func newFloat*(x: Int): Float =
new(result,finalizeFloat)
result = Float()
mpfr_init(result[])
mpfr_set_z(result[], x[], MPFR_RNDN)

func newFloat*(s: string, base: cint = 10): Float =
validBase(base)
new(result, finalizeFloat)
result = Float()
mpfr_init(result[])
if mpfr_set_str(result[], s, base, MPFR_RNDN) == -1:
raise newException(ValueError, "String not in correct base")

func newRat*(x: culong): Rat =
new(result, finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set_ui(result[], x, 1)
canonicalize(result)

func newRat*(x, y: culong): Rat =
new(result,finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set_ui(result[], x, y)
canonicalize(result)

func newRat*(x: int = 0): Rat =
new(result, finalizeRat)
result = Rat()
mpq_init(result[])
when isLLP64():
if x.fitsLLP64Long:
Expand All @@ -176,7 +176,7 @@ func newRat*(x: int = 0): Rat =
canonicalize(result)

func newRat*(x, y: int): Rat =
new(result, finalizeRat)
result = Rat()
mpq_init(result[])
when isLLP64():
var nref = mpq_numref(result[])
Expand Down Expand Up @@ -205,27 +205,27 @@ func newRat*(x, y: int): Rat =
canonicalize(result)

func newRat*(x, y: Int): Rat =
new(result,finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set_num(result[], x[])
mpq_set_den(result[], y[])
canonicalize(result)

func newRat*(x: float): Rat =
new(result,finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set_d(result[], x)
canonicalize(result)

func newRat*(x: Int): Rat =
new(result,finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set_z(result[], x[])
canonicalize(result)

func newRat*(s: string, base: cint = 10): Rat =
validBase(base)
new(result, finalizeRat)
result = Rat()
mpq_init(result[])
if mpq_set_str(result[], s, base) == -1:
raise newException(ValueError, "String not in correct base")
Expand All @@ -236,17 +236,17 @@ func newRat*(s: string, base: cint = 10): Rat =
#=======================================

func copyInt*(x: Int): Int =
new(result, finalizeInt)
result = Int()
mpz_init(result[])
mpz_set(result[], x[])

func copyFloat*(x: Float): Float =
new(result,finalizeFloat)
result = Float()
mpfr_init(result[])
mpfr_set(result[], x[], MPFR_RNDN)

func copyRat*(x: Rat): Rat =
new(result,finalizeRat)
result = Rat()
mpq_init(result[])
mpq_set(result[], x[])

Expand Down Expand Up @@ -1173,12 +1173,12 @@ func nextPrime*(x: Int): Int =

func clear*(z: Int) {.inline.} =
GCunref(z)
finalizeInt(z)
mpz_clear(z[])

func clear*(z: Float) {.inline.} =
GCunref(z)
finalizeFloat(z)
mpfr_clear(z[])

func clear*(z: Rat) {.inline.} =
GCunref(z)
finalizeRat(z)
mpq_clear(z[])
Loading

0 comments on commit e57e8df

Please sign in to comment.