* [PATCH] Complex.polar(x,0) should produce a RealNum
@ 2014-12-18 7:00 Jamison Hope
2014-12-18 18:12 ` Per Bothner
0 siblings, 1 reply; 2+ messages in thread
From: Jamison Hope @ 2014-12-18 7:00 UTC (permalink / raw)
To: kawa@sourceware.org list
[-- Attachment #1: Type: text/plain, Size: 627 bytes --]
This patch changes Complex#polar so that if its second argument (the
angle) is exact zero, then the result is a RealNum. This makes it
consistent with how Complex#make works.
Otherwise you end up with the strange situation of:
#|kawa:1|# (make-polar 3 0)
3.0
#|kawa:2|# (= (make-polar 3 0) 3.0)
#t
#|kawa:3|# (real? 3.0)
#t
#|kawa:4|# (real? (make-polar 3 0))
#f
#|kawa:5|# (make-polar 3 0):class
class gnu.math.DComplex
N.B. (real? (make-polar 3 0)) returns #t in all the other Schemes I
checked (Gambit, Guile, MIT, and Racket), but doing so is not
required by RnRS.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
[-- Attachment #2: polarzero.patch --]
[-- Type: application/octet-stream, Size: 1692 bytes --]
Index: gnu/math/ChangeLog
===================================================================
--- gnu/math/ChangeLog (revision 8230)
+++ gnu/math/ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2014-12-18 Jamison Hope <jrh@theptrgroup.com>
+
+ * Complex.java (polar): Change return type from DComplex to
+ Complex and return RealNum if angle is exact zero.
+ * DComplex.java (power): Update return type accordingly.
+
2014-11-17 Jamison Hope <jrh@theptrgroup.com>
Implemented quaternions.
Index: gnu/math/Complex.java
===================================================================
--- gnu/math/Complex.java (revision 8230)
+++ gnu/math/Complex.java (working copy)
@@ -110,13 +110,17 @@
return new DComplex(re, im);
}
- public static DComplex polar (double r, double t)
+ public static Complex polar (double r, double t)
{
+ if (t == 0.0)
+ return new DFloNum(r);
return new DComplex(r * Math.cos(t), r * Math.sin(t));
}
- public static DComplex polar (RealNum r, RealNum t)
+ public static Complex polar (RealNum r, RealNum t)
{
+ if (t.isZero() && t.isExact())
+ return r;
return polar(r.doubleValue(), t.doubleValue());
}
Index: gnu/math/DComplex.java
===================================================================
--- gnu/math/DComplex.java (revision 8230)
+++ gnu/math/DComplex.java (working copy)
@@ -126,8 +126,8 @@
return ((Numeric)y).divReversed(this);
}
- public static DComplex power (double x_re, double x_im,
- double y_re, double y_im)
+ public static Complex power (double x_re, double x_im,
+ double y_re, double y_im)
{
double h;
/* #ifdef JAVA5 */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Complex.polar(x,0) should produce a RealNum
2014-12-18 7:00 [PATCH] Complex.polar(x,0) should produce a RealNum Jamison Hope
@ 2014-12-18 18:12 ` Per Bothner
0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2014-12-18 18:12 UTC (permalink / raw)
To: kawa
On 12/17/2014 11:00 PM, Jamison Hope wrote:
> This patch changes Complex#polar so that if its second argument (the
> angle) is exact zero, then the result is a RealNum. This makes it
> consistent with how Complex#make works.
Thanks. I checked this in.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-18 18:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-18 7:00 [PATCH] Complex.polar(x,0) should produce a RealNum Jamison Hope
2014-12-18 18:12 ` Per Bothner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).