Comments (7)
Glad to know someone's making use of it! Keep in mind the most complete and well-tested implementation is the Fix64 type, the other ones were mainly for learning purposes.
from fixedmath.net.
Just for fun, why do you need fixed-point math for your game? If you need determinism I have written some guidelines for achieving that on .NET here: http://stackoverflow.com/a/19520769/154766
from fixedmath.net.
Determinism yes, that's interesting I'll have to look at that. I expected to run into problems with different achitectures, but figured "I'd cross that bridge when I came to it" except I was having a hell of a time with doubles on the same machine in the same function with the same input giving me different results, which lead me to finding out that it can decide at runtime which precision to use. I'm still not fully sure why it was deciding to change precision when it was, and it apeared to be stepping down precision, rather than up, which is suposedly impossible. http://stackoverflow.com/questions/20892957/floating-point-errors-with-same-input (when I was using doubles, it was sometimes giving me the same answer as when I tested again but casting a float)
changing to the FixedPoint datatype made the problem go away, and I didn't have to worry anymore.
from fixedmath.net.
I'm guessing you were compiling for x86? The reason is that the x86 CLR uses the x87 FPU, which internally uses 80-bit wide precision registers. This leads to more accurate although unpredictable results (depending on how exactly the code is compiled). The x64 CLR uses SSE which I believe is consistent.
Fix64 is consistent but somewhat slow (especially in x86! - in x64 at least it fits into registers) and cannot handle very large values well. It's faster than System.Decimal though.
I see that you made casts implicit in your version; I made them explicit to make the frontier between consistent and inconsistent math explicit in your code. With implicit conversions you might have floating-point math in places you wouldn't expect and this would introduce very hard to find bugs. I think this a sound design principle but of course you are free to use and modify the code as you please.
from fixedmath.net.
I think back then I was compiling for 'AnyCpu' on an x64 machine, however I was using some librarys which were x86 (http://www.ogre3d.org/tikiwiki/MOGRE)... huh, maybe that had something to do with it? I was getting the lower precision when calling from a class that 'used' mogre. where I was getting the higher precision, I was calling from a class that wasn't using any x86 librarys.
we're now compiling for x86 anyway, due to mogre being x86. we'll cross the bridge of building for x64 when we get a bit further along.
it seemed pretty safe to have implicit casts to the fixed math, unless I'm missing something. our objects are all using the fixed point number system where its needed. (we ended up using fix16 seems ok so far, just one thing gave us trouble was doing a sqrt which we bumped up to x64)
from fixedmath.net.
It sounds like MOGRE was setting FPU flags causing it to behave differently after you called into MOGRE. I suggest using Axiom instead, which is a fully managed implementation of OGRE and can be compiled for x64.
Beware that Fix16 has an extremely limited range and precision...
from fixedmath.net.
Mogre can be compiled for x64, though I've not yet attempted it. Axiom is I think even more versions behind Ogre than Mogre is. yeah we're going to have to keep an eye on the limited range of Fix16.
I've attempted to keep threading in mind as I've written the whole thing, so in the not too distant future I can play around with threading much of the calculations to improve any speed issues we have. I just have to be wary of messing up the deterministic side of it by doing so.
from fixedmath.net.
Related Issues (20)
- Could you add Pow()? HOT 3
- Seems to be possible to convert into hardware implementation HOT 6
- Is this library correct in terms of Base10 calculations? HOT 1
- ReflectionTypeLoadException: The classes in the module cannot be loaded. HOT 2
- request for Fixed32 too HOT 4
- Function Pow bug report HOT 1
- how to transfer by network? HOT 2
- A bug when use Acos() to 2 normalized vector HOT 2
- Suggestion adding **Fixed Point** keyword in description HOT 1
- Is changing "Fractional_Places" supported? HOT 2
- Using Math. for Fix32 HOT 6
- Debugging Determinism? (discussion) HOT 6
- Converting float to Fix64 consistent across CPU architectures? HOT 5
- Determinism HOT 3
- Suggestion: need profiling.
- Problem: Sqrt() for Q48.15 format implementation HOT 1
- FixedMath.Net with Net 3.5 (Unity3D) HOT 6
- Any plans to make all conversions deterministic? HOT 15
- Conversions from float and double are unspecified in case of overflow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fixedmath.net.