You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.
Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.
rem Store n as an integer, discarding the fraction.
n = n#
rem Adding n to itself reveals whether it should be rounded up or down:
rem Two halves make a whole, so fractions of at least 0.5 will be rounded up,
rem whereas two lesser fractions combined will fail to produce a whole number and therefore be rounded down.
rem This subtraction takes the integer value of n from the sum of 2n and discards the fraction by storing the
rem result in an integer variable. Now we see why the above addition was so important, because now all we
rem have left is an integer, so either n was rounded up or it's fraction wasn't large enough to do so.
n = n#-n
rem The function works for negative numbers too because we only ever talk in terms of n, so if n is negative, the addition and subtraction of n is also negative.
m# = n# + n#
a = int(m#)
b# = m# + m#
c# = int(b#-a) / 2.0
Login to post a reply