summary refs log tree commit diff stats
path: root/lib/pure/math.nim
Commit message (Expand)AuthorAgeFilesLines
...
* Merge pull request #7950 from Paalon/math-logAndreas Rumpf2018-06-141-5/+15
|\
| * Fix a testKoki Fushimi2018-06-141-1/+1
| * Use one same type for two parametersKoki Fushimi2018-06-141-5/+1
| * Use concrete expressionKoki Fushimi2018-06-051-7/+6
| * Bug fixKoki Fushimi2018-06-051-2/+3
| * Change to use log(x, base)Koki Fushimi2018-06-051-3/+3
| * Broaden the argument typesKoki Fushimi2018-06-041-1/+6
| * Generalize and add testKoki Fushimi2018-06-041-7/+14
| * Add log proc for base b of xKoki Fushimi2018-06-041-1/+3
* | Rename tgamma to gamma (#7929)Koki Fushimi2018-06-051-3/+10
* | Add product proc (#7951)Koki Fushimi2018-06-041-1/+13
|/
* Removed spaces in math moduledata-man2018-05-301-1/+1
* Use truncation division in mod for floats (#7118)Oscar Nihlgård2018-05-301-11/+40
* Add inverse hyperbolic, and cot, sec and csc; and their hyperbolic, inverse, ...Koki Fushimi2018-05-301-61/+96
* Faster binary gcd algorithm (#7849)Koki Fushimi2018-05-261-2/+30
* Fixes factorial's bugdata-man2018-05-171-1/+12
* Replace factorial function with a compile time one (#7276)notTito2018-05-041-4/+14
* fixes #6353 (#6951)skilchen2017-12-211-4/+13
* add missing math.trunc for js backend (#6950)skilchen2017-12-201-0/+2
* Add hint about computing powers between integers (#6419)Federico Ceratto2017-10-161-0/+2
* fixes #5966Fabian Keller2017-06-201-4/+7
* Add sgn() function to the math module (#5971)John Novak2017-06-151-0/+25
* bcc misses the same functions like vccAdrianV2016-12-281-1/+1
* Fixed #4532, VS2010 now can compile Nimandri lim2016-08-081-7/+86
* Removed trailing whitespace in math moduleMathijs Saey2016-08-051-1/+1
* Fixed #4574Mathijs Saey2016-08-051-1/+1
* Corrected comment in maths library.A. S. Budden2016-06-201-1/+1
* Update math.nimmatkuki2016-06-181-1/+1
* Windows MSVC < 2012 'round' function updatematkuki2016-06-171-5/+11
* Changed math.nim tests to use newly defined ==~ operatorA. S. Budden2016-05-311-24/+24
* Correction to round0 following review.A. S. Budden2016-05-311-1/+1
* Implemented function to split floating point numbers at the decimal place (eq...A. S. Budden2016-05-311-0/+25
* Modification to implementation of round() such that it returns a float and ac...A. S. Budden2016-05-311-25/+67
* moved random procs from math to its own module (breaking change)Andreas Rumpf2016-05-301-110/+0
* Merge branch 'patch-8' of https://github.com/apense/Nim into apense-patch-8Andreas Rumpf2016-05-301-52/+101
|\
| * Fixed silly format errorapense2015-06-241-1/+1
| * Converted tabsapense2015-06-241-39/+39
| * Rewrote procs for float32/float64apense2015-06-241-86/+128
* | Setting TAU to 2 * PIgmpreussner2016-03-171-1/+1
* | Added TAU constant.gmpreussner2016-03-171-0/+1
* | Removal of stats procs for openarray (use the RunningStat methodology)JamesP2015-11-111-20/+0
* | Removal of RunningStats ready for new stats.nim pure lib fileJamesP2015-11-071-42/+0
* | fix float comparision failure in math testsAman Gupta2015-10-021-1/+1
* | fixes #3312Araq2015-09-181-15/+14
* | math.nim works with NimScriptAraq2015-08-211-7/+9
* | Fix exponentiation operation to avoid overflow.Reimer Behrends2015-08-141-1/+3
* | Corrected erroneous descriptionapense2015-06-291-1/+2
* | Added some documentation and examplesapense2015-06-291-20/+47
* | disable vcc specific code which doesn't workAraq2015-06-291-39/+39
* | Merge pull request #2977 from apense/patch-5Andreas Rumpf2015-06-251-0/+13
|\ \ | |/ |/|
ss="sx">result result = prefix var (d, n, bias) = (0, InitialN, InitialBias) var (b, remaining) = (0, 0) for r in s.runes: if r.isBasic: # basic Ascii character inc b result.add($r) else: # special character inc remaining var h = b if b > 0: result.add(Delimiter) # we have some Ascii chars while remaining != 0: var m: int = high(int32) for r in s.runes: if m > int(r) and int(r) >= n: m = int(r) d += (m - n) * (h + 1) if d < 0: raise newException(PunyError, "invalid label " & s) n = m for r in s.runes: if int(r) < n: inc d if d < 0: raise newException(PunyError, "invalid label " & s) continue if int(r) > n: continue var q = d var k = Base while true: var t = k - bias if t < TMin: t = TMin elif t > TMax: t = TMax if q < t: break result.add($encodeDigit(t + (q - t) mod (Base - t))) q = (q - t) div (Base - t) k += Base result.add($encodeDigit(q)) bias = adapt(d, h + 1, h == b) d = 0 inc h dec remaining inc d inc n proc encode*(s: string): string {.raises: [PunyError].} = ## Encode a string that may contain Unicode. Prefix is empty. result = encode("", s) proc decode*(encoded: string): string {.raises: [PunyError].} = ## Decode a Punycode-encoded string var n = InitialN i = 0 bias = InitialBias var d = rfind(encoded, Delimiter) result = "" if d > 0: # found Delimiter for j in 0..<d: var c = encoded[j] # char if not c.isBasic: raise newException(PunyError, "Encoded contains a non-basic char") result.add(c) # add the character inc d else: d = 0 # set to first index while (d < len(encoded)): var oldi = i var w = 1 var k = Base while true: if d == len(encoded): raise newException(PunyError, "Bad input: " & encoded) var c = encoded[d]; inc d var digit = int(decodeDigit(c)) if digit > (high(int32) - i) div w: raise newException(PunyError, "Too large a value: " & $digit) i += digit * w var t: int if k <= bias: t = TMin elif k >= bias + TMax: t = TMax else: t = k - bias if digit < t: break w *= Base - t k += Base bias = adapt(i - oldi, runelen(result) + 1, oldi == 0) if i div (runelen(result) + 1) > high(int32) - n: raise newException(PunyError, "Value too large") n += i div (runelen(result) + 1) i = i mod (runelen(result) + 1) insert(result, $Rune(n), i) inc i when isMainModule: assert(decode(encode("", "bücher")) == "bücher") assert(decode(encode("münchen")) == "münchen") assert encode("xn--", "münchen") == "xn--mnchen-3ya"