Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: Turbo Pasca...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 16 Topic 199 of 215
Post > Topic >>

Re: Turbo Pascal question

by john <john@[EMAIL PROTECTED] > Dec 22, 2007 at 01:15 AM

Dr J R Stockton wrote:
> In comp.lang.pascal.ansi-iso message <f7OdnZKR3sNIXPfaRVnyuQA@[EMAIL PROTECTED]
>,
> Thu, 20 Dec 2007 19:29:28, Richard Heathfield <rjh@[EMAIL PROTECTED]
>
> posted:
>> john said:
>>
>>> Hi, regarding Turbo Pascal 7.x (or the standard), is there any power
>>> function provided?
>>>
>>> Something like
>>>
>>> power(10,4) meaning 10 ^4, or something similar.
>>
>> Pascal offers EXP and LN. N^P = EXP(P * LN(N)).
>>
>> Thus, 10^4 = EXP(4 * LN(10)).
> 
> The original example was an integer example, and you have given a float
> method.  I'm almost sure that your code will almost always give a float
> of exact integer value (if in the exact range 0..2^53 for Double and
> more for Extended).  That may not be good enough.
> 
> 
> For integer powers, one can use a multiplying loop, though that would
> get slow for 1.000001^1000000 (which gives about e); in which case one
> can be cunning as in (written in Borland, but perhaps generic) -
> 
>  function ExpNum(const A : Xtype ; const B : longint) : Xtype ;
>  begin if B=0 then ExpNum := 1.0 else
>     if Odd(B) then ExpNum := ExpNum(A, B-1) * A
>               else ExpNum := Sqr(ExpNum(A, B div 2)) ;
>   end {ExpNum} ;
> 
> which would for that do about log2(1000000) = 20 recursions.  It could
> be rewritten iterative.
> 
> My <URL:http://www.merlyn.demon.co.uk/pas-math.htm>
refers.
> 
> With an integer number to be raised to a power, a multiplying loop can
> never take unreasonably long, unless the number is -1 0 +1 or runtime
> checks are off.
> 
> 
> But the actual answer to the OP is "NO" or "NOT IN TP".


Yes, Richard's solution requires real, but I need to use longint.

More precisely, I want to do a program that provides and stores the 
reverse of a number. For example:


input: 12345

result: 54321


I am using div and mod to do that (with two longints and an array of 
longint), and having not thought any other way I can do the above, I 
can't use the elegant N^P= exp( P* ln(N) ); solution.

Is there any way I can do casting in Turbo Pascal 7.1 (like in C or C++)?
 




 16 Posts in Topic:
Turbo Pascal question
john <john@[EMAIL PROT  2007-12-20 21:09:11 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-20 19:29:28 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-21 13:44:12 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 01:15:05 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 01:38:43 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-22 00:58:29 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 13:18:49 
Re: Turbo Pascal question
Richard Heathfield <rj  2007-12-22 11:43:12 
Re: Turbo Pascal question
"Jochen" <jo  2007-12-22 22:42:57 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-23 01:33:35 
Re: Turbo Pascal question
"Jochen" <jo  2007-12-23 05:56:25 
Re: Turbo Pascal question
scott moore <nospam@[E  2007-12-23 10:33:04 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-24 00:59:51 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-22 17:51:06 
Re: Turbo Pascal question
john <john@[EMAIL PROT  2007-12-22 20:52:31 
Re: Turbo Pascal question
Dr J R Stockton <jrs@[  2007-12-23 16:36:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 23 15:59:03 CDT 2008.