[SERVER-6145] dividing two integers always produces a double Created: 20/Jun/12  Updated: 15/Aug/12  Resolved: 21/Jun/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Aaron Staple Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-6203 Aggregation operators should have wel... Backlog
Participants:

 Description   

Right now when one integer is divided by another the result is a double, even if the exact (unrounded) result could be expressed as an integer. This may be ok / desirable, but wanted to check.

Test:

c = db.c;
c.drop();
 
c.save( { a:NumberLong(10) } );
printjson( c.aggregate(
		       // Divide 10 by 1                                                          
                       { $project:{ z:{ $divide:[ '$a', NumberLong(1) ] } } },
		       // Match where z is of type double.                                        
                       { $match:{ z:{ $type:1 } } }
                       ) );



 Comments   
Comment by Eliot Horowitz (Inactive) [ 21/Jun/12 ]

This seems ok to me.
I'd rather be consistent and have division always return a double than only sometimes.

Generated at Thu Feb 08 03:10:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.