# Length to Float in

**URL:** <https://forums.sketchup.com/t/length-to-float-in/14855>\
**Category:** Ruby API\
**Created:** [September 5, 2015, 2:02am UTC](https://forums.sketchup.com/t/length-to-float-in/14855 "2015-09-05T02:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rojj](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@Rojj](https://forums.sketchup.com/u/Rojj)\
**Post date:** [September 5, 2015, 2:02am UTC](https://forums.sketchup.com/t/length-to-float-in/14855/1 "2015-09-05T02:02:23Z")

</div>

I am doing some profiling of my code and I have noticed that the conversion from Length to Float takes around 12% of the total execution.

```
 % cumulative self self total
 time seconds seconds calls ms/call ms/call name
 35.81 540.04 540.04 901584 0.60 4.45 Array#each
 12.46 727.90 187.86 31082436 0.01 0.01 Length#to_f
  3.24 1248.25 48.84 31099958 0.00 0.00 Float#to_f

```

The calculation can run for a few hours so this amount of time can become important.

Now. I know that SU uses inches internally and I have been quite careful (I think) in working only with internal units and exposing the model units only in the UI, but this conversion eludes me.

You can also notice that the number of calls to `Length#to_f` is almost exactly identical to `Float#to_f` (?) and this makes me suspicious.

I have read the ThomThom guide to units, but I could not find an answer to this.

Any idea?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 5, 2015, 4:01am UTC](https://forums.sketchup.com/t/length-to-float-in/14855/2 "2015-09-05T04:01:57Z")

</div>

Why do you think you need to convert **`Length`** objects to **`Float`** objects ?

As soon as you add, subtract, multiply or divide a **`Length`** object by any other **`Numeric`** subclass object, the result is a **`Float`** anyway. Even if the other object is a **`Length`**.

(On the C-side, **Length** are really **Float** type objects, that have overridden comparison methods, and some extra conversion methods.)

Are you explicitly calling **`Float#to_f`** in your code ? (Doing so serves no purpose. This might be happening “behind the curtain” because they are really float and are fooling the Ruby side.)

---

<div class="post-metadata">

**Author:** ![Rojj](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@Rojj](https://forums.sketchup.com/u/Rojj)\
**Post date:** [September 5, 2015, 4:31am UTC](https://forums.sketchup.com/t/length-to-float-in/14855/3 "2015-09-05T04:31:48Z")

</div>

Thanks Dan.

> [@DanRathbun](#):
>
> Are you explicitly calling Float#to\_f in your code ? (Doing so serves no purpose. This might be happening “behind the curtain” because they are really float and are fooling the Ruby side.)

No. The only values that I convert to `Float` are those that I read from external files. This morning I went through the code and insured that I was not not doing redundant conversions.

I understand that `Length` is a sub-class of `Float` and they should be almost the same things except for some specific methods like units conversions and geometric operations. So I imagined that once the conversion is done they would be treated as `Float`.

Say I ask the user for an input in meters. Internally I convert the input by doing

```
delta = input.m

```

and I continue all my calculations using `delta`. Does SU internally treats delta as a `Length` and for every operation makes a conversion to `Float`?
