how can 1/100=0

J

Junkone

cannot belive my eyes. how can 1/100 be equal to 0.
E:\Documents and Settings\Roasty>irb
irb(main):001:0> TRAILING_STOP=1/100
=> 0
irb(main):002:0> TRAILING_STOP
=> 0
irb(main):003:0>
 
P

Paolo Bonzini

cannot belive my eyes. how can 1/100 be equal to 0.
E:\Documents and Settings\Roasty>irb
irb(main):001:0> TRAILING_STOP=1/100
=> 0
irb(main):002:0> TRAILING_STOP
=> 0
irb(main):003:0>

in what languages it isn't?

$ python
Python 2.5.1 (r251:54863, May 12 2007, 11:15:25)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.0

(and C too, though I won't write the program here).

anyway, you can have 1/100 return a rational:

$ irb
irb(main):001:0> require 'mathn'
=> true
irb(main):002:0> 1/100
=> 1/100
irb(main):003:0> (1/100).denominator
=> 100

Paolo
 
T

Tim Hunter

Junkone said:
cannot belive my eyes. how can 1/100 be equal to 0.
E:\Documents and Settings\Roasty>irb
irb(main):001:0> TRAILING_STOP=1/100
=> 0
irb(main):002:0> TRAILING_STOP
=> 0
irb(main):003:0>

Try 1.0/100.0
 
J

Junkone

cannot belive my eyes. how can 1/100 be equal to 0.
E:\Documents and Settings\Roasty>irb
irb(main):001:0> TRAILING_STOP=1/100
=> 0
irb(main):002:0> TRAILING_STOP
=> 0
irb(main):003:0>

in what languages it isn't?

$ python
Python 2.5.1 (r251:54863, May 12 2007, 11:15:25)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.>>> 1/100

0

(and C too, though I won't write the program here).

anyway, you can have 1/100 return a rational:

$ irb
irb(main):001:0> require 'mathn'
=> true
irb(main):002:0> 1/100
=> 1/100
irb(main):003:0> (1/100).denominator
=> 100

Paolo

should 1/100=.01 ????
 
P

Paolo Bonzini

in what languages it isn't?
$ python
Python 2.5.1 (r251:54863, May 12 2007, 11:15:25)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.>>> 1/100

(and C too, though I won't write the program here).
anyway, you can have 1/100 return a rational:
$ irb
irb(main):001:0> require 'mathn'
=> true
irb(main):002:0> 1/100
=> 1/100
irb(main):003:0> (1/100).denominator
=> 100

should 1/100=.01 ????

Even in C, 1/100 = 0. But 1.0/100.0 or 1.0/100 or 1/100.0 = 0.01
because the division is done in floating-point math.

Paolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top