math


why has erlang redefined something as basic as a remainder?


All our mathematics books have been teaching us that a remainder is always positive. Wiki tells me that a remainder can be a least positive remainder or a least absolute remainder. It is a pretty basic concept which can be very difficult to unlearn for a lot people(including me). It could be cause of weird bugs when a programmer is working with multiple languages.
What is the reason behind erlang redefining such a basic concept?
Eshell V6.2 (abort with ^G)
1> -5 rem 3.
-2
This result is not consistent with either of Least Positive Remainder or Least Absolute Remainder Concept.
http://en.wikipedia.org/wiki/Remainder#Integer_division
It is because integer divisions are rounded towards 0.
It happens in many other programming languages, for example see this answer about C.
Indeed if you consider the division as being defined before the % operation, then we still expect a = (a / b) * b + (a % b). It then comes naturally that
5 / 3 = 1, so 5 % 3 == 2
-5 / 3 = -1, so 5 % 3 == -2
If we rounded toward -infinity instead of towards 0, then -5/3 would be -2, and % would be the modulus operator. Right now it is just a remainder of the division.

Related Links

Boolean formula encoding
Getting cells in a 2D grid between two angles
how to find the shortest distance in geomatry route?
how to reduce dimensionality of vector
Direction from a normalized vector
matrix norm that is invariant through a change of basis
Convert Cartesian point to point on rotated plane (pic)
Spot light cone direction rotation and orientation inversion
Adding two params of a predicate that aren't static
undefined reference to `tan' but math.h has been included
Computing which side of a line a point is [closed]
Solving the recurrence relation for number of nodes in an AVL tree?
how to cluster curve with kmeans?
Mathematical formula for inverse distance in a range [closed]
Drawing a star - what is sine and cosine actually in reference to?
Type-level arithmetics in OCaml

Categories

HOME
lua
applet
styling
chronicle
mocha
android-sms
stripe-payments
payment-processing
freebsd
wso2-das
calayer
wso2ei
uwsgi
w3.css
coreos
countdown
aerospike
broker
jqplot
addthis
php-carbon
abstract-syntax-tree
mathdotnet
jtable
effects
webfocus
clappr
petrel
apex-code
api-doc
increment
runc
weebly
jsonstore
h5py
logicblox
hawkular
textangular
phasset
msysgit
autofocus
default-browser
ewsjavaapi
sections
psycopg2
android-gps
database-cleaner
abbyy
ammonite
master-data-management
dwr
facebook-canvas
bosh-deployer
getelementbyid
asp.net-mvc-custom-filter
db2400
masspay
lapply
activity-diagram
file-management
ota
vimeo-ios
pddl
mysqladmin
clientid
linqtocsv
armv7
actioncable
spymemcached
phone-number
protected
diagonal
iife
llvm-gcc
centering
chatjs
mpj-express
clearcase-remote-client
notifydatasetchanged
image-scaling
nitrogen
keyboard-navigation
magento-1.6
simpleaudioengine
re2c
shift
micro-orm
sparc
argumentexception
slimbox
mixing
arr
google-profiles-api
ria
mdi
ladon
sdl.net
blackberry-jde
xmltextwriter
etrade-api
hunchentoot
nsindexset
executescalar
network-scan
net-ssh
utility
large-teams

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App