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

Calculating sqrt and arcTan in javacard without float type
Move point in cartesian coordinate through distance in the given direction
LU-Decomposition factorization error
How to find polygons in a given set of points and edges?
Calculate how much a point is worth based on played games
LibGDX: How to keep an Object at same visual screen position while rotating the camera
Setting the magnitude of a 2D Vector
Convert Lat/Long to X,Y position within a Bounding Box
d3js Cluster Force Layout IV block by Mike
Maximum number of points that lie on the same straight straight line in a 2D plane
How to draw a gps marker on a rotated custom image map
Conversion coordinates from a bound rectangle, to the coordinates of rotated rectangle contained by it
Why isn't this Math.random method working?
Calculate radius of curve/arc formed by line segments (approximate)
The Probability of … After n Trials
Finding minima of a function using genetic algorithm

Categories

HOME
elastic-beanstalk
mongodb
music
runnable
auth0
blogs
image-segmentation
redhat
webdriver-io
sweetalert
apple-mail
drag
eloqua
smartsheet-c#-sdk-v2
garmin
ssrs-2008
centroid
aspdotnetstorefront
jcrop
robotium
liferay-aui
naturallyspeaking
epicorerp
toolbar
rrd
asana-api
feedly
android-imageview
clappr
json-c
evercookie
p4-lang
presto
jdom-2
kmdf
vtable
joe-editor
ipod-touch
uitabbarcontroller
h5py
monogame
wp-api
opal
android-calendar
notimplementedexception
infiniband
unityscript
geneticsharp
shift-reduce-conflict
setwindowshookex
data-fitting
telecommunication
pager
app-engine-ndb
jongo
intrinsics
highslide
google-api-ruby-client
ctakes
materialdrawer
autopy
nominatim
multiscreen
avalonedit
telescope
cbc-mode
pencilblue
swift-array
imake
setattribute
tab-delimited
culture
publish-actions
monk
image-scaling
nhunspell
asciiencoding
jxta
disabled-input
array-address
modx-evolution
shift
sugar.js
couchpotato
loadlibrary
datadesign
alternate-data-stream
timespan
file-structure
cakephp-2.1
squirrelmail
hiphop
cellphone
formsauthentication
high-traffic
drupal-gmap
gumstix
iphone-sdk-3.1

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