R function for find he exp not working properly for Vector -5:5

Solution for R function for find he exp not working properly for Vector -5:5
is Given Below:

I have tried to write a sample function for exp. Its working for positive value vectors like 1:5. But it’s not working for -5 : 5. Could you please help me to correct the function?

    myexp = function(x){
      rold = 0
      rnew = 1
      i=1
      while(all(rnew != rold)){
        rold = rnew
        rnew = rnew +  x^i/factorial(i)
        i = i + 1
      }
      rnew
    }

The following code is working

myexp(1:5)

Following code is not working

myexp(-5:5)

Testing should be true for the following code

x <- seq(-5, 20)
all.equal(myexp(x), exp(x))