# FloatVectorOperations Divide

**URL:** https://forum.juce.com/t/floatvectoroperations-divide/15512
**Category:** General JUCE discussion
**Created:** [September 10, 2015, 3:16pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512 "2015-09-10T15:16:51Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![darrenw2112](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@darrenw2112](https://forum.juce.com/u/darrenw2112)
#### Post date: [September 10, 2015, 3:16pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/1 "2015-09-10T15:16:51Z")

</div>

Can divide operations be added to this library?&nbsp; I use these quite a bit and it would be nice if it were built in.

```
//in BasicOps32

static forcedinline ParallelType div (ParallelType a, ParallelType b) noexcept { return _mm_div_ps (a, b); }
```

&nbsp;

```
//in BasicOps64

static forcedinline ParallelType div (ParallelType a, ParallelType b) noexcept { return _mm_div_pd (a, b); }
```

&nbsp;

```
void JUCE_CALLTYPE FloatVectorOperations::copyWithDividend(float* dest, const float* src, float dividend, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_svdiv(&dividend, src, 1, dest, 1, (vDSP_Length)num);
   
#else

        JUCE_PERFORM_VEC_OP_SRC_DEST(dest[i] = dividend / src[i], Mode::div(divsd,s),

        JUCE_LOAD_SRC, JUCE_INCREMENT_SRC_DEST,

        const Mode::ParallelType divsd = Mode::load1(dividend);)

#endif

    }
```

&nbsp;

```
void JUCE_CALLTYPE FloatVectorOperations::copyWithDivide (float* dest, const float* src, float divisor, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_vsdiv(src, 1, &divisor, dest, 1, (vDSP_Length)num);

#else

        JUCE_PERFORM_VEC_OP_SRC_DEST(dest[i] = src[i] / divisor, Mode::div( s,divs),

        JUCE_LOAD_SRC, JUCE_INCREMENT_SRC_DEST,

        const Mode::ParallelType divs = Mode::load1(divisor);)

#endif

}
```

&nbsp;

```
void JUCE_CALLTYPE FloatVectorOperations::divide(float* dest, const float* src1, const float* src2, int num) noexcept 

    {

#if JUCE_USE_VDSP_FRAMEWORK

        vDSP_vdiv(src2,1,src1,1,dest,1, (vDSP_Length) num);

#else

        JUCE_PERFORM_VEC_OP_SRC1_SRC2_DEST(dest[i] = src2[i] / src1[i], Mode::div(s1, s2), JUCE_LOAD_SRC1_SRC2, JUCE_INCREMENT_SRC1_SRC2_DEST, )

#endif

    }
```

Thanks,

Darren

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)
#### Post date: [September 10, 2015, 3:30pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/2 "2015-09-10T15:30:36Z")

</div>

Thanks - yes, we're planning on adding a lot more DSP functionality soon!

---

<div class="post-metadata">

### Author: ![fefanto](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fefanto/32/1518_2.png) [@fefanto](https://forum.juce.com/u/fefanto)
#### Post date: [June 21, 2018, 2:39pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/3 "2018-06-21T14:39:32Z")

</div>

bump… would really love to have an optimized buffer division in floatVectorOperations.

---

<div class="post-metadata">

### Author: ![vastdynamics](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vastdynamics/32/4254_2.png) [@vastdynamics](https://forum.juce.com/u/vastdynamics)
#### Post date: [June 23, 2018, 1:01pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/4 "2018-06-23T13:01:49Z")

</div>

+1  
And optimized buffer trunc, modf please:  
[my post](https://forum.juce.com/t/add-convertfloattofixed-to-floatvectoroperations-to-vectorized-truncate-a-float-buffer/27650)

---

<div class="post-metadata">

### Author: ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)
#### Post date: [March 12, 2019, 5:34pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/5 "2019-03-12T17:34:20Z")

</div>

+1!

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [March 12, 2019, 6:20pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/6 "2019-03-12T18:20:39Z")

</div>

Should be moved into the new category `Feature Requests`, so people can vote for it…

---

<div class="post-metadata">

### Author: ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)
#### Post date: [November 10, 2022, 12:41pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/7 "2022-11-10T12:41:35Z")

</div>

Please vote for my feature request 🙂

> [@FloatVector divide or at least 1/x?](https://forum.juce.com/t/floatvector-divide-or-at-least-1-x/53634):
>
> This is really painfully missing, or have I perhaps overlooked it, is there a fast method for this? Here is also an old thread with source-code, would be nice if this will implemented in juce soon. wink

---

<div class="post-metadata">

### Author: ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)
#### Post date: [November 10, 2022, 1:52pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/8 "2022-11-10T13:52:13Z")

</div>

but why? can’t you basically do

```auto
auto numInv = 1.f / num;
FloatVectorOperations::multiply(data, numInv, numSamples);

```

i would also like there to be more floatvectoroperations tho. for example modulo and maybe one or some for dry wet operations like a + m \* (b - a), where a, b and m are all buffers of blockSize, because of parameter smoothing etc

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [November 10, 2022, 1:59pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/9 "2022-11-10T13:59:30Z")

</div>

> [@Mrugalla](#):
>
> but why? can’t you basically do
> 
> ```auto
> auto numInv = 1.f / num;
> FloatVectorOperations::multiply(data, numInv, numSamples);
> 
> ```

That’s not realy the same. In your example the divider is constant, which allows the alternative version. But the feature request is about getting the inverse of each value in the array, like this pseudo code:

```auto
for (size_t i=0; i < vector.size(); ++i)
    vector [i] = 1.0 / vector [i];

```

(at least that’s the interesting one. The FR mentions different formulas)

---

<div class="post-metadata">

### Author: ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)
#### Post date: [November 10, 2022, 2:00pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/10 "2022-11-10T14:00:22Z")

</div>

oh oops. didn’t think of that. you’re absolutely right! that reminds me. a floatVectorOp of sqrt buffers would be cool too. (used for instance in equal loudness curve dry/wet).

also one for 1 - x, with x being the buffer

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [November 10, 2022, 2:44pm UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/11 "2022-11-10T14:44:33Z")

</div>

> [@Mrugalla](#):
>
> also one for 1 - x, with x being the buffer

This is possible in two passes:

```auto
multiply (ptr, -1.0f, numValues);
add (ptr, 1.0f, numValues);

```

not sure it helps, not knowing the use case…

---

<div class="post-metadata">

### Author: ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)
#### Post date: [October 1, 2025, 11:29am UTC](https://forum.juce.com/t/floatvectoroperations-divide/15512/12 "2025-10-01T11:29:48Z")

</div>

just a small 10years anniversary bump. note that there is an FR opened to votes here:

> [@FloatVector divide or at least 1/x?](https://forum.juce.com/t/floatvector-divide-or-at-least-1-x/53634):
>
> This is really painfully missing, or have I perhaps overlooked it, is there a fast method for this? Here is also an old thread with source-code, would be nice if this will implemented in juce soon. wink
