Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
ceil() misbehaving
Chris_D_Mentes_001
Member, csevp Posts: 102 PRO
I'm trying to round up a value but:
1. ceil(1) or ceil(1,1) return 1 and roundToPrecision(2,0) returns 2 as expected.
2. ceil((2405mm-1200mm)/(1200mm+5mm),1) returns 2 ??
3. roundToPrecision((2405mm+5mm)/(1200mm+5mm),0) returns 3 ??
Please tell me what I am doing wrong here!
1. ceil(1) or ceil(1,1) return 1 and roundToPrecision(2,0) returns 2 as expected.
2. ceil((2405mm-1200mm)/(1200mm+5mm),1) returns 2 ??
3. roundToPrecision((2405mm+5mm)/(1200mm+5mm),0) returns 3 ??
Please tell me what I am doing wrong here!
0
Best Answers
-
_anton Member, Onshape Employees Posts: 410#2 is because ((2405mm-1200mm)/(1200mm+5mm) is equal to slightly more than 1 because of floating-point math, and the ceil(..., 1) rounds it up to the next multiple of 1, which is 2.
For #3, I'm getting 2.1 -
NeilCooke Moderator, Onshape Employees Posts: 5,671Yes, everything is stored in meters.Senior Director, Technical Services, EMEAI2
Answers
For #3, I'm getting 2.
According to this link https://www.h-schmidt.net/FloatConverter/IEEE754.html I can see that I shouldn't have errors unless rather then FS units storing values with units as milimeters it actually stores them as meters. In other words 1200mm in the value with units type map is stored as 1.200 and units is meter.
This seems to be consistant as I've tested it with a couple FS scripts:
For those who are in rounding hell as I have been for the last 3 hours heres what you need to know,
do not work with valuewithunits. Multiply you value by 1000 and divide my millimeter. after this you can manipulate this number to your hears contet only going back to value with units at the last second
To elaborate further values in onshape are stored using the IEEE standard 64 bit floating point number, however the "decimal" representation makes a meter 1 not 1000. Because of this the actual number stored has an error which you can see using this link: https://www.h-schmidt.net/FloatConverter/IEEE754.html.
As an example 50 millimeters is actually 50.0000007450580596923828125 millimeters:
BUT if you multiply by 1000 all of a sudden you elimiate the floating point error (or at least shift it further back):
hence the recomended practice