Vector2 precision
I'm finding Vector2's precision to be completely unsuitable for my app (a sketching application with lots of trigonometry), and I'm wondering what the sanctioned Vector with double precision elements are? There was the one in WPF, of course, but for a universal app we can't use that. There is Point, but it doesn't provide much of the necessary math. Are people just rolling their own when they need it?
Unfortunately, we don't have any primitives exposed right now that have 64-bit precision. The primitives we do expose are the ones that map to the Universal platform's numerics primitives (Windows.Foundation.Numerics), which all use floats.
Could you give a little more detail about some of the operations you are doing and what you'd like a double-precision structure to look like? Would a Vector2d, identical to Vector2 but with double's instead of float's, be useful for you?
Angle computations mostly. My angles are represented as doubles, so going back and forth between vectors loses a lot of precision. All I really need is Vector2 with the same API and double components. Though I’m wondering why universal is bothering with floats at all (unlike WPF, which was double-only)? I guess it must be because of IoT and gaming hardware, or does it have to do with SIMD optimizations?
From: Eric Mellino [mailto:[email protected]] Sent: Friday, January 8, 2016 4:12 AM To: dotnet/corefx [email protected] Cc: Sean McDirmid [email protected] Subject: Re: [corefx] Vector2 precision (#5222)
Unfortunately, we don't have any primitives exposed right now that have 64-bit precision. The primitives we do expose are the ones that map to the Universal platform's numerics primitives (Windows.Foundation.Numerics), which all use floats.
Could you give a little more detail about some of the operations you are doing and what you'd like a double-precision structure to look like? Would a Vector2d, identical to Vector2 but with doubles instead of floats, be useful for you?
— Reply to this email directly or view it on GitHubhttps://github.com/dotnet/corefx/issues/5222#issuecomment-169792152.
I'm no expert on this but my experience with .NET Micro Framework showed that Single and Double operations had exact same performance on the supported micro-controllers. Why do all libraries still use Single?
Why do all libraries still use Single?
Well, not all libraries use Single, like @mcdirmid mentioned, WPF used 64-bit floats. As for why the new Vector types are single-precision, it's a combination of the following:
- They are the .NET projections of some core Windows numeric types, which use 32-bit floats.
- Almost all graphics and game-related libraries use 32-bit floats as opposed to 64-bit floats.
- Physics libraries also generally use 32-bit floats.
- Direct3D and OpenGL have more limited support for using double-precision floats.
- The new types are more or less identical to the types used in XNA, which uses 32-bit floats. Being part of a game library/framework, the above bullet points explain why floats were used.
@mellinoe I understand but that's the lowest common denominator solution. Because of legacy, it's impossible to improve. Rendering and physics libraries are finally adopting multi-threading, they'll adopt 64-bit floats sooner or later. Most new smartphone now comes with 64-bit processors. You can have a 64-bit computer just for $15: https://www.kickstarter.com/projects/pine64/pine-a64-first-15-64-bit-single-board-super-comput I've been writting Point implementations and converting between library implementations for way too long. I have one of the implementations available on Nuget and it's been downloaded more than 1K times: https://www.nuget.org/packages/HydraMF.Math/ I'm hoping System.Numerics will finally end this nightmare. :) In a slightly different subject, I just wish there could be a generics-based numerics implementation. I already tried and I know it's a complex subject. Thanks for listening, Antao
Given the current state and purpose of System.Numerics.Vectors, I don't think we want to do this right now. If this is something community members want to pursue, here's some of the points we'd need to understand and design for:
- Does the type need to be hardware-accelerated?
- Does the type need to be in System.Numerics.Vectors.dll? Historically, this only contains SIMD-accelerated types, and has lots of limitations due to the fact that it is an in-box assembly in .NET Framework. I would strongly recommend a design which does not place non-essential types in System.Numerics.Vectors.dll.
- Should the design incorporate other less-mainstream vector types, like
Int32,Int64, etc.? - Should this design interoperate with WPF in some way?
I'll close this out now, but am open to discussing a proposal that addresses some of the above in a new issue.