CANVAS Gotcha (Precision)

Been playing around with the <CANVAS> tag. Overall, it works pretty well. However, there was this little bit o’ joy: The transforms are all based on 32-bit floats. (See the WebKit code, e.g. translate, transform, &c.) Since 32-bit floats only give you 23 bits of mantissa, you have to be careful when working with very large domains.

Converting all your coordinates to be relative to your viewport origin (in 64-bit JS) seems to work OK, although it is a bit hacky.

I’m not sure why someone would decide to use 32-bit floats in this context — “this context” being a browser that must also support JavaScript and its 64-bit floats. Maybe some mobile platforms don’t support double-precision FP, and so this was written to the lowest common denominator.

Share and Enjoy:
  • Twitter
  • Facebook
  • Digg
  • Reddit
  • HackerNews
  • del.icio.us
  • Google Bookmarks
  • Slashdot
This entry was posted in Web stuff. Bookmark the permalink.

Comments are closed.