db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@debrunners.com>
Subject [PATCH] Derby-225 - handle negative scale from BigDecimal
Date Wed, 27 Apr 2005 19:32:22 GMT

Attached is a patch that handles the negative scale for a BigDecimal
that can occur in J2SE 5.0 onwards.

I would appreciate other eyes looking at it to ensure the handling of
negative scale is correct.

Previously BigDecimals always had a zero or postive scale. A negative
scale means that the value is the unscaled value * 10^(-scale).

// e.g. 1000 can be represented by:
//    a BigDecimal with scale -3 (unscaled value of 1)
// or a BigDecimal with scale 0 (unscaled value of 1000)

The change is really two parts

1) Ensure that the SQL precision and scale (e.g. DECIMAL(5,2) has SQL
precision 5 and scale 2) is calculated correctly in J2SE 5.0 from a
BigDecimal value. This includes using the new precision method when
running in J2SE 5.0 and handling negative scale values correctly.
Comments were also added to clarify that methods were returning the
SQL precision and scale, and this differs for BigDecimal's definition
precision and scale.

e.g. the above BigDecimal values representing 1000 both have SQL
precision and scale of (3,0), but have BigDecimal precision and scale of
(1,-3) and (3,0).

2) Define and implement that the on-disk format of a DECIMAL for Derby
always has a zero or positive scale, so that all values written to disk
are independent of the JVM being used. So a database created by J2SE 5.0
 is portable to J2SE 1.3/1.4.

It passes all the tests under jdk 1.4 and jdk 1.5, though I need to
verify the jdk 1.5 test runs as I had to halt it late in the run.

I'll commit it sometime in the next week, addressing any comments.

Thanks,
Dan.

M      java\engine\org\apache\derby\iapi\types\SQLDecimal.java
M      java\engine\org\apache\derby\iapi\types\NumberDataValue.java

Mime
View raw message