[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math floordiv function gives incorrect result #56130

Closed
mattbarrett98 opened this issue May 17, 2022 · 5 comments
Closed

math floordiv function gives incorrect result #56130

mattbarrett98 opened this issue May 17, 2022 · 5 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting response Status - Awaiting response from author TF 2.8 type:bug Bug

Comments

@mattbarrett98
Copy link
mattbarrett98 commented May 17, 2022
Click to expand!

Issue Type

Bug

Source

source

Tensorflow Version

2.8

Custom Code

No

OS Platform and Distribution

No response

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

The code 

import tensorflow as tf
x = tf.constant([1e-37], dtype=tf.float32)
y = tf.constant([-2.0], dtype=tf.float32)
tf.math.floordiv(x, y)

works as expected, giving
<tf.Tensor: shape=(1,), dtype=float32, numpy=array([-1.], dtype=float32)>.

However

import tensorflow as tf
x = tf.constant([1e-38], dtype=tf.float32)
y = tf.constant([-2.0], dtype=tf.float32)
tf.math.floordiv(x, y)

gives
<tf.Tensor: shape=(1,), dtype=float32, numpy=array([-0.], dtype=float32)>.

Any idea why when x gets small enough it starts to output -0. rather than -1.. 1e-38 is still in range for float32 I believe so I think it should still work?



### Standalone code to reproduce the issue

```shell
https://colab.research.google.com/drive/1J583b0h11hee3UItK6l4VyaJ_hG7J4AT#scrollTo=c4-4DQ72QPZy

Relevant log output

No response

@sushreebarsa
Copy link
Contributor

@chunduriv I was able to replicate the issue on colab , please find the gist here for your reference.
Thank you!

@chunduriv
Copy link
Contributor

@mattbarrett98,

This is an intended behavior and the same can also be seen in all cases mentioned below

Using TF without dtype

import tensorflow as tf
x = tf.constant([1e-38])
y = tf.constant([-2.0])
print(tf.math.floordiv(x, y))

Output:

tf.Tensor([-0.], shape=(1,), dtype=float32)

Using math module

import tensorflow as tf
from math import floor
x2 = tf.constant([1e-38], dtype=tf.float32)
y2 = tf.constant([-2.0], dtype=tf.float32)
print(floor(x2/y2))

Output:

0

Using Python

x3 = tf.constant([1e-38], dtype=tf.float32)
y3 = tf.constant([-2.0], dtype=tf.float32)
print(x3//y3)

tf.Tensor([-0.], shape=(1,), dtype=float32)

Thank you.

@chunduriv chunduriv added the stat:awaiting response Status - Awaiting response from author label Jun 16, 2022
@mattbarrett98
Copy link
Author

I see, thanks for your help!

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jun 16, 2022
@chunduriv
Copy link
Contributor

@mattbarrett98,

Please feel free to close the issue if it is resolved? Thank you.

@chunduriv chunduriv added the stat:awaiting response Status - Awaiting response from author label Jun 16, 2022
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stat:awaiting response Status - Awaiting response from author TF 2.8 type:bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants