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

FloatArray prevents rounding #1873

Closed
capocasa opened this issue Feb 21, 2016 · 4 comments
Closed

FloatArray prevents rounding #1873

capocasa opened this issue Feb 21, 2016 · 4 comments

Comments

@capocasa
Copy link
Member

0.02 Is a floating point number. However, if it is inside a FloatArray, that number will never be reached precisely, which can cause rounding errors.

a=FloatArray[0.1];

expected:
=> FloatArray[ 0.1 ]

actual:
=> FloatArray[ 0.10000000149012 ]

a[0] = a[0].round(0.01);

expected:
=> FloatArray[ 0.1 ]

actual:
=> FloatArray[ 0.10000000149012 ]

This works:

a[0].round(0.01);
=> 0.1

a[0].round(0.01).class;
=> Float

@redFrik
Copy link
Contributor

redFrik commented Feb 21, 2016

nothing strange. it has been discussed many times on the sc-users mailing list for example in the 'Strange modulo behavior' thread.
or use a=DoubleArray[0.1];

@telephon
Copy link
Member

Why not use an Array directly?

@capocasa
Copy link
Member Author

@telephon To avoid making a copy of a FloatArray from a SoundFile.

@capocasa
Copy link
Member Author

@jamshark70 's explanation in #1874 clears it up.

@telephon telephon closed this as completed Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants