My favorites
▼
|
Sign in
hxcpp
Runtime files for c++ backend for haxe
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
173
attachment: hxcppModulo.patch
(1.6 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Index: include/hx/Operators.h
===================================================================
--- include/hx/Operators.h (revision 474)
+++ include/hx/Operators.h (working copy)
@@ -86,7 +86,7 @@
double Mod(TL inLHS,TR inRHS) { return hx::DoubleMod(inLHS,inRHS); }
#if !defined(_MSC_VER) || _MSC_VER > 1399
-inline int Mod(int inLHS,int inRHS) { return inLHS % inRHS; }
+inline int Mod(int inLHS,int inRHS) { if(inRHS==0) return 0; return inLHS % inRHS; }
#endif
Index: src/Math.cpp
===================================================================
--- src/Math.cpp (revision 474)
+++ src/Math.cpp (working copy)
@@ -141,12 +141,32 @@
double DoubleMod(double inLHS,double inRHS)
{
- if (inRHS==0) return 0;
- double divs = inLHS/inRHS;
- double lots = divs<0 ? ::floor(-divs) : ::floor(divs);
- return inLHS - lots*inRHS;
+
+/*Implementation without the use of fmod*/
+ if (inRHS==0.0 || Math_obj::isNaN(inLHS) || Math_obj::isNaN(inRHS) || !Math_obj::isFinite(inLHS)) return Math_obj::NaN;
+ if (inLHS==0.0) return 0.0;
+
+
+ bool neg=(inLHS<0.0);
+ double temp =inLHS;
+ if (neg) inLHS=-inLHS;
+ if (Math_obj::isFinite(inRHS)) {
+ temp = inLHS/inRHS;
+ double lots=temp<0.0? ceil(temp):floor(temp);
+ temp = inRHS>0 ? inLHS - lots * inRHS : -lots * inRHS + inLHS;
+ } else if (inRHS<0 && inLHS<0) temp=-temp;
+ if (neg && temp>=0) temp=-temp;
+ return temp;
+/*Implementation with the use of fmod*/
+
+/* if (!Math_obj::isNaN(inRHS) && !Math_obj::isFinite(inRHS) && Math_obj::isFinite(inLHS)) {
+ return inLHS;
+ }
+ return fmod(inLHS,inRHS);*/
+
}
}
+
Powered by
Google Project Hosting