about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-04-21 12:54:51 -0700
committerbors <bors@rust-lang.org>2013-04-21 12:54:51 -0700
commit6a31525c50fc5f2e2ad63bf30ec80c1279bf1fe4 (patch)
tree5d5efc584aa00328b3df8fc6eecefb5532c19ac8 /src/libsyntax
parent535244cde4640986f29978c5f9c35fd3b40f58db (diff)
parent01eb5e8ad39a57e9fc31569983c1b9d5905a7e58 (diff)
downloadrust-6a31525c50fc5f2e2ad63bf30ec80c1279bf1fe4.tar.gz
rust-6a31525c50fc5f2e2ad63bf30ec80c1279bf1fe4.zip
auto merge of #5990 : bjz/rust/rem-quot, r=catamorphism
This renaming, proposed in the [Numeric Bikeshed](https://github.com/mozilla/rust/wiki/Bikeshed-Numeric-Traits#rename-modulo-into-rem-or-remainder-in-traits-and-docs), will allow us to implement div and and modulo methods that follow the conventional mathematical definitions for negative numbers without altering the definitions of the operators (and confusing systems programmers). Here is a useful answer on StackOverflow that explains the difference between `div`/`mod` and `quot`/`rem` in Haskell: (When is the difference between quotRem and divMod useful?)[http://stackoverflow.com/a/339823/679485].

This is part of the numeric trait reforms tracked in issue #4819.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs2
-rw-r--r--src/libsyntax/ast_util.rs8
-rw-r--r--src/libsyntax/parse/parser.rs4
-rw-r--r--src/libsyntax/parse/prec.rs2
4 files changed, 8 insertions, 8 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index b0b3e45abe5..a086a1db0aa 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -389,7 +389,7 @@ pub enum binop {
     add,
     subtract,
     mul,
-    div,
+    quot,
     rem,
     and,
     or,
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 910c9857d2d..f0a14b39049 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -80,7 +80,7 @@ pub fn binop_to_str(op: binop) -> ~str {
       add => return ~"+",
       subtract => return ~"-",
       mul => return ~"*",
-      div => return ~"/",
+      quot => return ~"/",
       rem => return ~"%",
       and => return ~"&&",
       or => return ~"||",
@@ -103,8 +103,8 @@ pub fn binop_to_method_name(op: binop) -> Option<~str> {
       add => return Some(~"add"),
       subtract => return Some(~"sub"),
       mul => return Some(~"mul"),
-      div => return Some(~"div"),
-      rem => return Some(~"modulo"),
+      quot => return Some(~"quot"),
+      rem => return Some(~"rem"),
       bitxor => return Some(~"bitxor"),
       bitand => return Some(~"bitand"),
       bitor => return Some(~"bitor"),
@@ -348,7 +348,7 @@ pub fn is_self(d: ast::def) -> bool {
 /// Maps a binary operator to its precedence
 pub fn operator_prec(op: ast::binop) -> uint {
   match op {
-      mul | div | rem   => 12u,
+      mul | quot | rem   => 12u,
       // 'as' sits between here with 11
       add | subtract    => 10u,
       shl | shr         =>  9u,
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e892f212b05..42275aca0a3 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -21,7 +21,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer};
 use ast::{bind_by_copy, bitand, bitor, bitxor, blk};
 use ast::{blk_check_mode, box, by_copy, by_ref};
 use ast::{crate, crate_cfg, decl, decl_item};
-use ast::{decl_local, default_blk, deref, div, enum_def};
+use ast::{decl_local, default_blk, deref, quot, enum_def};
 use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again};
 use ast::{expr_assign, expr_assign_op, expr_binary, expr_block};
 use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
@@ -1786,7 +1786,7 @@ pub impl Parser {
                   token::PLUS => aop = add,
                   token::MINUS => aop = subtract,
                   token::STAR => aop = mul,
-                  token::SLASH => aop = div,
+                  token::SLASH => aop = quot,
                   token::PERCENT => aop = rem,
                   token::CARET => aop = bitxor,
                   token::AND => aop = bitand,
diff --git a/src/libsyntax/parse/prec.rs b/src/libsyntax/parse/prec.rs
index 79adabec9b7..d8c829740fa 100644
--- a/src/libsyntax/parse/prec.rs
+++ b/src/libsyntax/parse/prec.rs
@@ -31,7 +31,7 @@ pub static as_prec: uint = 11u;
 pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
   match tok {
       BINOP(STAR)    => Some(mul),
-      BINOP(SLASH)   => Some(div),
+      BINOP(SLASH)   => Some(quot),
       BINOP(PERCENT) => Some(rem),
       // 'as' sits between here with 11
       BINOP(PLUS)    => Some(add),