Giter Site home page Giter Site logo

Comments (5)

LiarPrincess avatar LiarPrincess commented on June 10, 2024

[3.2.2023] EDIT to main issue:

from swift-numerics.

LiarPrincess avatar LiarPrincess commented on June 10, 2024

Things to do in Helpers (but I'm not going to update 15 PRs, so we will do it later):

  • add reserveCapacity in generate[Big]Ints - this does not matter in normal tests (count ~1000), but it matters in performance tests where we need to generate 100_000 values

  • rename BigIntPrototype.compare -> BigIntPrototype.compareMagnitude

  • rewrite BigIntPrototype.create - shifts 10x faster than multiplication:

    internal static func create<T: FixedWidthInteger>(
      isPositive: Bool,
      magnitude: [T]
    ) -> BigInt {
      assert(!T.isSigned)
      var result = BigInt()
    
      for (index, word) in magnitude.enumerated() {
        var bits = BigInt(word)
        bits <<= index * T.bitWidth
        result |= bits
      }
    
      if !isPositive {
        result.negate()
      }
    
      return result
    }

    If we use sign+magnitude with UInt as Word then there is another possible optimisation that avoids calculations altogether.

from swift-numerics.

LiarPrincess avatar LiarPrincess commented on June 10, 2024

I wrote Violet XsProMax which is a Violet implementation with following changes:

  • no small inlined integer (Smi) - magnitude is always stored on the heap
  • no restrictions on the size - isNegative is stored in-line (and not on the heap like in Violet); count and capacity are on the heap because I don't want to stray too much from Violet.

Which gives us:

struct BigInt {
  struct Header {
    var count: UInt32
    var capacity: UInt32
  }

  var flags: UInt8
  var buffer: ManagedBufferPointer<Header, UInt>
}

I updated the performance PR with the results.

from swift-numerics.

mgriebling avatar mgriebling commented on June 10, 2024

The issue below (from @LiarPrincess) appears fixed in my latest updates (see pull request #261)

// -9223372036854775808 = Int64.min, obviously '-Int64.min' overflows
let int: Int64 = -9223372036854775808
let big = BigInt(int)
XCTAssertEqual(-big, big * -1)

from swift-numerics.

mgriebling avatar mgriebling commented on June 10, 2024

All remaining issues (at least the published ones) appear to have been fixed with the pull request #262.
There were some problems with division/modulo signs, initialization, corner-case fixes.

from swift-numerics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.