-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: @Max/@Min with double
PostPosted: Wed Mar 04, 2009 8:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
We have been discussing the possibility of allowing @Min and @Max to get double values instead of the current long.
There are various problems with that though.

http://firstclassthoughts.co.uk/java/tr ... traps.html
explains a lot of traps around double

Quote:
To evaluate @Min @Max we do comparison so

say @Max(2.3d) applied on 2.2999999999999997d

System.out.println(2.2999999999999997d < 2.3d); => displays false
System.out.println(new BigDecimal(""+2.2999999999999997d).compareTo(
new BigDecimal(""+2.3d) ) == -1); => displays false
System.out.println( new BigDecimal(9223372036854775807l).compareTo(new
BigDecimal(9223372036854775807d)) == 0 ); => displays false

not a pleasant surprise


To which Sebastian replies

Quote:
You have the same problem when the max value is a long:

System.out.println(0.99999999999999997d < 1L);

So one part is the question do we support the @Max for float and double
properties? And if so how do we address this issue?


So

1. do we support float and double for @Min / @Max?
2. if 1 is yes, I'd be inclined to say the value should be double but that's not fully automatic.

Thoughts?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 8:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the only way that will work is to use string and pass it to BigDecimal.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 10:45 pm 
Newbie

Joined: Wed Mar 04, 2009 10:42 pm
Posts: 1
Or you could rely on some configurable delta


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 5:39 pm 
Newbie

Joined: Tue Nov 21, 2006 6:46 pm
Posts: 6
I hate to say this, but
1. double validation is absolute must (otherwise ability to model real world using JSR 303 will be severely limited)
2. @tolerance (optional, with default as 0.0d) annotation have to be introduced to let #1 work in most of the cases


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.