Ravin Singh D
Ravin Singh D

Reputation: 893

tensorflow float32 decimal precision

when trying Tensorflow intro i came across the following code

w=tf.Variable(.3,tf.float32)
b=tf.Variable(-.3,tf.float32)

while printing this values it gives following output

print(sess.run(w))
print(sess.run(b))
print(sess.run([w]))
print(sess.run([b]))

Output

-0.3
-0.3
[0.30000001]
[-0.30000001]

why while print as array it gives extra floating point precision? Is there any documentation related this topic?

Upvotes: 0

Views: 2225

Answers (1)

keveman
keveman

Reputation: 8487

Here is a great resource to answer this question. To paraphrase the first paragraph on that web page :

TensorFlow isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .3 == .30000001.

Upvotes: 1

Related Questions