charto / bigfloat

Fast arbitrary precision math library for computational geometry.
MIT License
74 stars 4 forks source link

SystemJs dependency & precision #2

Closed munrocket closed 5 years ago

munrocket commented 5 years ago

Can't add bigfloat.js without system.js in project and also set number of limb to achieve desired precision.

jjrv commented 5 years ago

For setting precision, you can call .truncate or .round on the final result.

This is an npm package so in browsers you're supposed to use a loader like SystemJS or WebPack. I'll re-think that in the next version.

This package really needs a rewrite now that I found your link to Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates. It has a far better approach, and exactly the same focus: robust geometry.

munrocket commented 5 years ago

Yep, I had this article in references. But if you need just robust polygon clipping you can find new algorithm. For example algo that converges fast to solution without invering matrix. I think it's better in term of number of floating point operations because renormalization algorithm become pretty heavy if you replace each component in matrix by this numbers. In double.js you need 27 flop to division, imagine how much it will take for more components.

munrocket commented 5 years ago

I see you updated BigFloat and looking forward with this library.

I am trying to benchmark it in browser and for UMD format we need to add require.js on page like this

<script src="https://cdn.jsdelivr.net/npm/bigfloat@0.1.1/dist/umd/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js"></script>

As you know IIFE in rollup works like sharm without any dependecy. Can you add it in autoroll? Here proper config example:

//rollup.config.js
export default {
  input: 'src/mySource.js',
  output: {
    file: 'bundle.iife.js',
    format: 'iife',
    name: 'MyBundle'
  }
};
jjrv commented 5 years ago

For me this was enough:

<script>
var exports = {};
</script>
<script src="https://cdn.jsdelivr.net/npm/bigfloat@0.1.1/dist/umd/index.js"></script>

Then you can use it like:

var BigFloat32 = bigfloat.BigFloat32;
var x = new BigFloat32(1);
munrocket commented 5 years ago

Ok when I will have free time I will add PR.

munrocket commented 5 years ago

@jjrv, do you tested bigfloat53? For some reason it’s not working for me, but bigfloat32 is ok.