Recent

Author Topic: Nth root  (Read 4612 times)

Don_Zagor

  • New Member
  • *
  • Posts: 25
Nth root
« on: December 30, 2018, 05:31:39 pm »
How can i find the Nth root in Pascal?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Nth root
« Reply #1 on: December 30, 2018, 05:47:53 pm »
For the square root use sqrt();, for any n use power() from unit Math, e.g.
Code: Pascal  [Select][+][-]
  1. power(64, 1/3);
for the third root etc.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Nth root
« Reply #2 on: December 30, 2018, 05:48:22 pm »
Nth root of x equals x^(1/n) IIRC.
Power(x, 1/n) (unit Math) might do the trick?

Bart

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Nth root
« Reply #3 on: December 30, 2018, 05:56:46 pm »
This works too:
Code: Pascal  [Select][+][-]
  1. 64**(1/3)
but unit Math must be in uses since operator ** is overloaded there.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018