db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Satheesh Bandaram <sathe...@Sourcery.Org>
Subject Re: Bug in division operator with numeric operands?
Date Mon, 20 Mar 2006 22:23:56 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Also note your script would work if you had used a precision of <b>30</b>,
instead of 31.<br>
<br>
ij&gt; CREATE TABLE t (d1 DOUBLE, d2 DOUBLE, n1 NUMERIC(<b>30</b>,11),
n2 NUMERIC(<b>30</b>,11));<br>
0 rows inserted/updated/deleted<br>
ij&gt; INSERT INTO t VALUES (1.5, 2.5, 1.5, 2.5);<br>
1 row inserted/updated/deleted<br>
ij&gt; SELECT d1/d2, n1/n2, n1*(1.0/n2) FROM t;<br>
1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|3<br>
<br>
--------------------------------------------------------------------------------<br>
0.6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|0.6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|0.60000000000000000000<br>
<br>
1 row selected<br>
<br>
Satheesh<br>
<br>
Satheesh Bandaram wrote:<br>
<blockquote cite="mid441F1C3F.7030501@Sourcery.Org" type="cite">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
Hi Matthias,<br>
  <br>
Matthias Ohlemeyer wrote:
  <blockquote cite="mid1142884547.9203.0.camel@localhost.localdomain"
 type="cite">
    <pre wrap="">Hi,

I've been trying to port a relatively complex application from Oracle to
Derby for quite a while now, but it seems like I've hit a road block
now.

Can somebody explain the following behaviour? I copied the following
input-output sequence from ij:
  </pre>
  </blockquote>
I can help, if you promise to share our experience of porting your
application from Oracle to Derby. <span class="moz-smiley-s1"><span>
:-) </span></span><br>
What kind of issues you faced and how easy or difficult was it etc...<br>
  <blockquote cite="mid1142884547.9203.0.camel@localhost.localdomain"
 type="cite">
    <pre wrap="">CREATE TABLE t (d1 DOUBLE, d2 DOUBLE, n1 NUMERIC(31,11), n2
NUMERIC(31,11));
INSERT INTO t VALUES (1.5, 2.5, 1.5, 2.5);
SELECT d1/d2, n1/n2, n1*(1.0/n2) FROM t;

1           |2                 |3

----------------------------------------------------------------
0.6         |0                 |0.600000000000000000000000000000

1 row selected
  </pre>
  </blockquote>
This seems like a simple bug, <b>at the first look</b>.&nbsp; If you look
at NumericTypeCompiler code, which calculates the scale and precision
of operation result type, the comments and the code doesn't seem to
match. (<b>getScale()</b> method) I would suggest filing a bug in JIRA.<br>
  <br>
I can provide more help in resolving the issue.<br>
  <br>
Satheesh <br>
  <br>
  <u><b>NumericTypeCompiler.java</b></u><br>
  <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if (TypeCompiler.DIVIDE_OP.equals(operator))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
/*<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
** Take max left scale + right precision - right scale + 1,
  <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
** or 4, whichever is biggest <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
*/<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
LanguageConnectionContext lcc = (LanguageConnectionContext)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
(ContextService.getContext(LanguageConnectionContext.CONTEXT_ID)); <br>
  <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<b>
// Scale: 31 - left precision + left scale - right scale<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
val = Math.max(NumberDataValue.MAX_DECIMAL_PRECISION_SCALE
- lprec + lscale - rscale, 0);</b><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
  <br>
Here val is returning <b>zero </b>for scale, it seems.<br>
  <br>
</blockquote>
</body>
</html>


Mime
View raw message