Welcome Guest!
 EUforum
 Previous Message All Messages Next Message 
Glitch in floor() function?  Mike Wever
 Jun 26, 2008 12:00 PDT 


posted by: Mike Wever <mewever at ?mail.c?m>

Hi, all. I was trying to write a function to round a number and uncovered what
seems to be a glitch in the floor() function.

This code:
<eucode>
include get.e

procedure round(atom x, integer precision)
integer mult

mult = power(10, precision)
printf(1, "initial: %f\n", {x})
x *= mult
printf(1, "shifted right: %f\n", {x})
x += 0.5
printf(1, "plus rounding half: %f\n", {x})
x = floor(x)
printf(1, "floor: %f\n", {x})
x /= mult
printf(1, "shifted left: %f\n", {x})
end procedure

round(1.5,0)
puts(1, "\n")
round(1.05,1)
puts(1, "\n")
round(1.005,2)
puts(1, "\n")
round(1.0005,3)

if wait_key() then end if
</eucode>

produces these results:
initial: 1.500000
shifted right: 1.500000
plus rounding half: 2.000000
floor: 2.000000
shifted left: 2.000000

initial: 1.050000
shifted right: 10.500000
plus rounding half: 11.000000
floor: 11.000000
shifted left: 1.100000

initial: 1.005000
shifted right: 100.500000
plus rounding half: 101.000000
floor: 100.000000
shifted left: 1.000000

initial: 1.000500
shifted right: 1000.500000
plus rounding half: 1001.000000
floor: 1001.000000
shifted left: 1.001000

It seems that floor(101) gave a result of 100. Is this an error or am I
missing something?
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.