Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize add and sub #8

Open
Patashu opened this issue Nov 21, 2017 · 2 comments
Open

optimize add and sub #8

Patashu opened this issue Nov 21, 2017 · 2 comments
Labels
is this optimal? possible performance improvements

Comments

@Patashu
Copy link
Owner

Patashu commented Nov 21, 2017

add/sub has some vestigal weirdness that has the correct functionality, but probably isn't optimal or as simple as possible.

https://bitbucket.org/heldercorreia/speedcrunch/src/9cffa7b674890affcb877bfebc81d39c26b20dcc/src/math/floatnum.c?at=master&fileviewer=file-view-default

  • float_add
  • float_sub
  • _addsub_ordered
@Patashu Patashu added the is this optimal? possible performance improvements label Nov 21, 2017
@Patashu
Copy link
Owner Author

Patashu commented Dec 27, 2017

The recent changes to add/sub to improve integer arithmetic (toNumber has a similar but simpler kludge too) have tanked their performance by 4x. Would be nice to either have the correct integer arithmetic while not sacrificing performance, or maybe to have two versions so you pick what you want.

@Patashu Patashu changed the title optimize add and sub by looking at how SpeedCrunch does it optimize add and sub Dec 27, 2017
@Patashu
Copy link
Owner Author

Patashu commented Oct 2, 2018

Transport Defender has a really neat add that I need to check for performance/accuracy.

  public static BigNum operator +(BigNum bn1, BigNum bn2)
  {
    long num = Math.Abs(bn1.Exponent - bn2.Exponent);
    if (bn1.Exponent > bn2.Exponent)
    {
      bn2.Base /= Math.Pow(10.0, (double) num);
      bn2.Exponent += num;
    }
    else if (bn1.Exponent < bn2.Exponent)
    {
      bn1.Base /= Math.Pow(10.0, (double) num);
      bn1.Exponent += num;
    }
    return new BigNum(bn1.Base + bn2.Base, bn1.Exponent);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is this optimal? possible performance improvements
Projects
None yet
Development

No branches or pull requests

1 participant