Upon further research looks like:
=> *(/ 1 0.0)*
Infinity
triggers this method: clojure.lang.Numbers.*divide(long, double)*
*static public double divide(long x, double y){
return x / y;
}*
=>* (/ 1.0 0)*
Infinity
triggers this method: clojure.lang.Numbers.*divide(double, long)*
*static public double divide(double x, long y){
return x / y;
}*
=> *(/ 1 0)*
ArithmeticException Divide by zero clojure.lang.Numbers.divide
(Numbers.java:157)
triggers this method: clojure.lang.Numbers.*divide(Object, Object)*
*static public Number divide(Object x, Object y){
Ops yops = ops(y);
if(yops.isZero((Number)y))
throw new ArithmeticException("Divide by zero");
return ops(x).combine(yops).divide((Number)x, (Number)y);
}*
On Tue, Oct 30, 2012 at 8:20 PM, AtKaaZ <[email protected]> wrote:
> As I tested, looks like when either of the args are double ie. 1.0 instead
> of 1
> then the code that checks for and shows divide by zero is not reached,
> which is this code:
> static public Number divide(Object x, Object y){
> Ops yops = ops(y);
> if(yops.isZero((Number)y))
> throw new ArithmeticException("Divide by zero");
> return ops(x).combine(yops).divide((Number)x, (Number)y);
>
> }
>
>
>
> On Tue, Oct 30, 2012 at 3:52 PM, Tim Olsen <[email protected]>wrote:
>
>> Hello Clojurians.
>>
>> Normally by some IEEE floating-point standard, division by 0.0 should
>> give Infinity (or NaN if the divisor is also 0.0). This is the case
>> when using primitive doubles in clojure:
>>
>> (/ 1.0 0.0)
>> => Infinity
>>
>> And even when using boxed Doubles in java:
>>
>> public class BoxedDoubleDivideZero {
>>
>> public static void main(String[] args) {
>> Double a = new Double(4.0);
>> Double b = new Double(0.0);
>>
>> System.out.println(a/b);
>> }
>> }
>>
>> $ javac BoxedDoubleDivideZero.java
>> $ java BoxedDoubleDivideZero
>> Infinity
>>
>> But it is not the case when using boxed Doubles in clojure:
>>
>> (/ (Double. 1.0) (Double. 0.0))
>> ArithmeticException Divide by zero clojure.lang.Numbers.divide
>> (Numbers.java:156)
>>
>> Is this considered a bug or feature?
>>
>> Thanks,
>> Tim
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>>
>
>
>
> --
> I may be wrong or incomplete.
> Please express any corrections / additions,
> they are encouraged and appreciated.
> At least one entity is bound to be transformed if you do ;)
>
>
--
I may be wrong or incomplete.
Please express any corrections / additions,
they are encouraged and appreciated.
At least one entity is bound to be transformed if you do ;)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en