• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert long number to string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert long number to string


  • Subject: Re: Convert long number to string
  • From: Graff <email@hidden>
  • Date: Sun, 18 Apr 2004 04:51:16 -0400

On Apr 18, 2004, at 2:41 AM, Gnarlodious wrote:

Entity Graff spoke thus:

You can use dc instead but it uses reverse polish notation
Did someone say RPN? That's for me!

echo `date +%s` `date +%s` 604800 % - p | dc
you can duplicate the second evaluation with 'd':
echo `date +%s` d 604800% - p | dc

for comparison here is the line written for bc:

echo `date +%s` - `date +%s` % 604800 | bc

As you can see, the bc command is a bit easier to comprehend.
Not for a Forthhead like me. Graff, are you saying the 'echo' command piles
a bunch of stuff on a stack and 'bc' evaluates it all endfirst?


The echo basically sets up a string which the bc and dc commands evaluate. Polish Notation is prefix notation, it puts the operators first and then the operands follow. Reverse Polish Notation is postfix notation, it puts the operands before the operators. "Normal" Notation is infix notation, you put the first operand then the operator then the second operand. Infix notation is what most people use when they do math, it uses the order of operation rules to determine what order the math should be done. Polish and Reverse Polish notation use the sequence of the operators and operands to determine the order of the math.

For bc an addition string ends up being:

a + b

The result is then sent to either the next level of evaluation or is sent to stdout if there is no next level.

For dc an addition string is:

a b +

The result is pushed back onto the stack so that any further operations can be performed on it.

For example bc would handle doing a + b * c like this:

Initial string needed:
a + b * c
First operation:
b * c = d
New string (internal, you don't see it)
a + d
Second operation:
a + d = e
Third operation:
e printed to stdout

dc would handle doing a + b * c like this:

Initial string needed:
b c * a + p
First operation:
b c * = d // push d
Stack after first operation:
d a +
Second operation:
d a + = e // push e
Stack after second operation:
e
Third operation:
p // print e to stdout

- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Convert long number to string (From: Gnarlodious <email@hidden>)

  • Prev by Date: Re: InDesign - get old/latest file path of missing link
  • Next by Date: Re: Using GUI Scripting to set window positions
  • Previous by thread: Re: Convert long number to string
  • Next by thread: Re: Convert long number to string
  • Index(es):
    • Date
    • Thread