0

Below is some code where I divide some numbers (transformerFromPDFToMk.tx, transformerFromPDFToMk.ty) by a scale.

for node in scene.rootNode.childNodes {

   node.position = SCNVector3Make(-Float(transformerFromPDFToMk.tx) / scale + node.position.x, node.position.y, -Float(transformerFromPDFToMk.ty) / scale + node.position.z)

   ...

}

The scale is this number output in the console:

Optional(2127.32227)

and the tx/ty values are:

81145541.6402883 -- tx
99399613.5798074 -- ty

After the division the number only has one decimal place:

38144.5 --- node position after init: x
46725.2 --- node position after init: y

I was wondering if I could keep the precision of the two numbers being divided, in the answer, after dividing them.

ewizard
  • 2,801
  • 4
  • 52
  • 110
  • `Float` has a precision of 6-7 decimal digits, so your input values are already less precise than your think they are. – Martin R Mar 05 '18 at 20:39
  • See https://stackoverflow.com/questions/24051314/precision-string-format-specifier-in-swift for information about values vs. their printed representation. – Phillip Mills Mar 05 '18 at 20:42
  • hmm...so you think its just how the number is being represented by a string? or maybe the `scale` value is a double actually? – ewizard Mar 05 '18 at 20:47
  • If you can convert your math to Double, I suggest that's the best start. If you still see a problem, investigate formatting. – Phillip Mills Mar 05 '18 at 21:03
  • If i convert everything to double dont i lose the precisiont? I'm trying to scale down the size of an AR world so when its scaled down...1 meter is only a fraction of a unit in the ar space...so the decimal places are relevant – ewizard Mar 05 '18 at 21:08
  • basically i want my ar world to be smaller without compromising units/meter...so that when there is a change in movement it is recognized – ewizard Mar 05 '18 at 23:10
  • In fact, `Double` has twice as much decimal places as `Float` (so-called double-precision), hence the name `Double`. – Dan Karbayev Mar 05 '18 at 23:20
  • Interesting...I'll get on changing it then – ewizard Mar 05 '18 at 23:21
  • some of the functions im using require float..i wasn't able to improve anything – ewizard Mar 06 '18 at 00:20
  • I was looking at the link..it seems like it is more for formatting numbers as strings...i can tell that it is probably not formatted in an abbreviated way because my scene nodes dont change position with the changes in x and y – ewizard Mar 06 '18 at 01:27

0 Answers0