michitaro / healpix

An implementation of HEALPix in JavaScript / TypeScript
MIT License
14 stars 4 forks source link

Maximum supported order? #8

Closed cdeil closed 6 years ago

cdeil commented 6 years ago

@michitaro - What is the maximum supported norder?

I see 16 here: https://github.com/michitaro/healpix/blob/90c15ade239c525c0966e34f5022bb792ea45a47/spec/generate-testcase.py#L39

Why is that?

Naively I would think that orders up to 24 can be supported, given that JS has numbers that can represent int up to 53 bit:

>>> import healpy as hp
>>> hp.nside2npix(hp.order2nside(24)) / (2 ** 53)
0.375

I think healpy supports up to order 29, because they have 64 bit integers available.

>>> import healpy as hp
>>> hp.nside2npix(hp.order2nside(29))
3458764513820540928
>>> hp.nside2npix(hp.order2nside(29)) / (2 ** 64)
0.1875

CC @tboch

michitaro commented 6 years ago

This module uses many bit-wise operations. Bit-wise operations in JS deal with only 32bit integers. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators

So this module deals with only numbers less than 32bit integers.

cdeil commented 6 years ago

@michitaro - Then do you understand why the functions work for norder up to 16?

With 32 bit (or 31 bit for unsigned) I would have expected only order up to 13 or 14 to work properly:

>>> import healpy as hp
>>> hp.nside2npix(hp.order2nside(16)) / (2 ** 32)
12.0
>>> hp.nside2npix(hp.order2nside(15)) / (2 ** 32)
3.0
>>> hp.nside2npix(hp.order2nside(14)) / (2 ** 32)
0.75
>>> hp.nside2npix(hp.order2nside(14)) / (2 ** 31)
1.5
>>> hp.nside2npix(hp.order2nside(13)) / (2 ** 31)
0.375
michitaro commented 6 years ago

I may misunderstand you question, but...

The real limit is on ipix not on nside. The limit comes from these 2 functions. https://github.com/michitaro/healpix/blob/6d512edef4803d88a1a6794309730342c1e7c9cc/src/index.ts#L503 https://github.com/michitaro/healpix/blob/6d512edef4803d88a1a6794309730342c1e7c9cc/src/index.ts#L524

While calculating ipix with norder >= 16 hit these limits, alculating nside with norder doesn't hit the limit.

cdeil commented 6 years ago

So if higher norder support is not easily added, could you please document the limit in the README (after #9)?

I'm new to TS / JS and number crunching there, so I don't know, but this might be relevant? https://github.com/Microsoft/TypeScript/issues/15096 https://github.com/Microsoft/TypeScript/wiki/Roadmap#30-july-2018

michitaro commented 6 years ago

So if higher norder support is not easily added, could you please document the limit in the README (after #9)?

Support for higher norder is not easy. I'll document the limitation.

I'm new to TS / JS and number crunching there, so I don't know, but this might be relevant?

Yes. After most browsers support Bigint, we can use Bigint for higher norder.

cdeil commented 6 years ago

I'll document the limitation.

I see https://github.com/michitaro/healpix#limitations

@michitaro - Thank you!