all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Drew Adams <drew.adams@oracle.com>
Cc: raman <raman@google.com>, Emacs developers <emacs-devel@gnu.org>,
	Tino Calancha <tino.calancha@gmail.com>
Subject: RE: New library num-base-converters
Date: Tue, 15 Aug 2017 15:35:10 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1708151518070.14915@calancha-pc> (raw)
In-Reply-To: <84387000-0545-4a51-8644-772b6b53165c@default>

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]



On Mon, 14 Aug 2017, Drew Adams wrote:

>> One point of this library is the convenience of not having to
>> know anything about neither calculator.el nor calc.el to get
>> the answer with easy.
>>
>> Every Emacs user will understand the following:
>> M-x nbc-hex2dec ff RET
>> "ff hexadecimal = 255 decimal"
>>
>> M-: (nbc-oct2dec "644") RET
>> => 420
>>
>> ;; Or just `hex2dec' and `oct2dec' if you customize
>> ;; `nbc-define-aliases' to non-nil.
>
> (format "%d" #xff)  ; hex to decimal
> --> "255"
>
> (format "%x" 255)   ; decimal to hex
> --> "ff"
>
> (format "%d" #o644) ; octal to decimal
> --> "420"
>
> (format "%o" 420)   ; decimal to octal
> --> "644"
For an user familiar with the Emacs '#' read syntaxis might be OK.
But for the average user, it's better to accept more input formats:
(nbc-hex2dec "#xff")
"255"
(nbc-hex2dec "ff")
"255"
(nbc-hex2dec "0xff")
"255"



> And didn't Pascal B. point this out in the thread previously cited?
>
>    (format "#8r%o #10r%d #16r%x" 42 42 42)
>    --> "#8r52 #10r42 #16r2a"

*) cannot be called interactively.
*) This covers the base range 2 <= b <= 16.  Even worse, it silently
    returns a wrong result for b > 16:
(format "#16r%x" 42)
"#16r2a"
(format "#17r%x" 42)
"#17r2a"
(format "#37r%x" 42)
"#37r2a"

Compare with:

(nbc-number-base-converter "42" 10 16)
"2A"
(nbc-number-base-converter "42" 10 17)
"28"
(nbc-number-base-converter "42" 10 37)
;; Signal error: Base ‘b’ must satisfy 2 <= b <= 36: base-in ‘10’ base-out 
‘37’

  reply	other threads:[~2017-08-15  6:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-14 17:26 New library num-base-converters Tino Calancha
2017-08-14 17:48 ` Ted Zlatanov
2017-08-15  2:11   ` raman
2017-08-15  2:50     ` Tino Calancha
2017-08-15  5:25       ` Drew Adams
2017-08-15  6:35         ` Tino Calancha [this message]
2017-08-15  7:55 ` Stefan Monnier
2017-08-15  9:49   ` Tino Calancha
2017-08-15 15:24     ` Stefan Monnier
2017-08-15 13:40   ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1708151518070.14915@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=raman@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.