Decimal prefix for numbers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Decimal prefix for numbers

Venks Izod
[First time posting here - please pardon transgressions]

I am a hardware (ASIC) designer and often code in Verilog - in
addition to Tcl and C and many other languages.

Verilog (and other Hardware Description Languages) always (or at least
since the 1995 LRM) had a way to specify a decimal number explicitly.
Verilog uses 'd343534 to mean decimal, VHDL actually allows any radix
from 2 to 16 using syntax, so you could explicitly force a decimal
interpretation using 10#343534#.

Tcl now allows 0b for binary in [expr] and [format], which is similar
to 'b in verilog.  And of cource 0o and 0x have always hbeen around.

Would it be good to add 0d for explicit decimal?

I had asked on the chat and one upside is to prevent false parsing of
leading 0's in [clock formats] as octal, without having to go through
a scan.

But a more elegant reason is that it makes the radix definition
consistent, so (a) all valid input radixes have a consistent
unambiguous input literal format and (b) the d in [format %d] finally
finds its complement in scan.


Thanks

Venks on the chat


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Brian Griffin-4

> On May 23, 2017, at 11:28 PM, Venks Izod <[hidden email]> wrote:
>
> [First time posting here - please pardon transgressions]
>
> I am a hardware (ASIC) designer and often code in Verilog - in
> addition to Tcl and C and many other languages.
>
> Verilog (and other Hardware Description Languages) always (or at least
> since the 1995 LRM) had a way to specify a decimal number explicitly.
> Verilog uses 'd343534 to mean decimal, VHDL actually allows any radix
> from 2 to 16 using syntax, so you could explicitly force a decimal
> interpretation using 10#343534#.
>
> Tcl now allows 0b for binary in [expr] and [format], which is similar
> to 'b in verilog.  And of cource 0o and 0x have always hbeen around.
>
> Would it be good to add 0d for explicit decimal?
>
> I had asked on the chat and one upside is to prevent false parsing of
> leading 0's in [clock formats] as octal, without having to go through
> a scan.
>
> But a more elegant reason is that it makes the radix definition
> consistent, so (a) all valid input radixes have a consistent
> unambiguous input literal format and (b) the d in [format %d] finally
> finds its complement in scan.

A reasonable request, I'm all for it.  It just needs a TIP.  Here's the implementation:

$ fossil diff generic/tclStrToD.c
Index: generic/tclStrToD.c
==================================================================
--- generic/tclStrToD.c
+++ generic/tclStrToD.c
@@ -661,10 +661,15 @@
            }
            if (c == 'o' || c == 'O') {
                explicitOctal = 1;
                state = ZERO_O;
                break;
+           }
+           if (c == 'd' || c == 'D') {
+               flags |= TCL_PARSE_INTEGER_ONLY;
+               state = DECIMAL;
+               break;
            }
 #ifdef TCL_NO_DEPRECATED
            goto decimal;
 #endif
            /* FALLTHROUGH */


-Brian


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Brian Griffin-4

> On May 25, 2017, at 8:08 AM, Brian Griffin <[hidden email]> wrote:
>
>>
>> On May 23, 2017, at 11:28 PM, Venks Izod <[hidden email]> wrote:
>>
>> [First time posting here - please pardon transgressions]
>>
>> I am a hardware (ASIC) designer and often code in Verilog - in
>> addition to Tcl and C and many other languages.
>>
>> Verilog (and other Hardware Description Languages) always (or at least
>> since the 1995 LRM) had a way to specify a decimal number explicitly.
>> Verilog uses 'd343534 to mean decimal, VHDL actually allows any radix
>> from 2 to 16 using syntax, so you could explicitly force a decimal
>> interpretation using 10#343534#.
>>
>> Tcl now allows 0b for binary in [expr] and [format], which is similar
>> to 'b in verilog.  And of cource 0o and 0x have always hbeen around.
>>
>> Would it be good to add 0d for explicit decimal?
>>
>> I had asked on the chat and one upside is to prevent false parsing of
>> leading 0's in [clock formats] as octal, without having to go through
>> a scan.
>>
>> But a more elegant reason is that it makes the radix definition
>> consistent, so (a) all valid input radixes have a consistent
>> unambiguous input literal format and (b) the d in [format %d] finally
>> finds its complement in scan.
>
> A reasonable request, I'm all for it.  It just needs a TIP.  Here's the implementation:
>
> $ fossil diff generic/tclStrToD.c
> Index: generic/tclStrToD.c
> ==================================================================
> --- generic/tclStrToD.c
> +++ generic/tclStrToD.c
> @@ -661,10 +661,15 @@
>            }
>            if (c == 'o' || c == 'O') {
>                explicitOctal = 1;
>                state = ZERO_O;
>                break;
> +           }
> +           if (c == 'd' || c == 'D') {
> +               flags |= TCL_PARSE_INTEGER_ONLY;
> +               state = DECIMAL;
> +               break;
>            }
> #ifdef TCL_NO_DEPRECATED
>            goto decimal;
> #endif
>            /* FALLTHROUGH */

This feature is fully implemented in branch bsg-0d-radix-prefix.

-Brian



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Venks Izod
Thanks Brian,  I can see you're an expert at this stuff - tests docs and all.

I'm still trying to figure out how to TIP this.   The TIP process says to say email dkf,  
but dkf is obviously busy with bigger sheds than this..

Are there alternatives to a tip?    Show of emails?   We have +2 and -0 so far.  
Unianimous :).

-Venkat


On Sat, May 27, 2017 at 3:45 PM, Brian Griffin <[hidden email]> wrote:

> On May 25, 2017, at 8:08 AM, Brian Griffin <[hidden email]> wrote:
>
>>
>> On May 23, 2017, at 11:28 PM, Venks Izod <[hidden email]> wrote:
>>
>> [First time posting here - please pardon transgressions]
>>
>> I am a hardware (ASIC) designer and often code in Verilog - in
>> addition to Tcl and C and many other languages.
>>
>> Verilog (and other Hardware Description Languages) always (or at least
>> since the 1995 LRM) had a way to specify a decimal number explicitly.
>> Verilog uses 'd343534 to mean decimal, VHDL actually allows any radix
>> from 2 to 16 using syntax, so you could explicitly force a decimal
>> interpretation using 10#343534#.
>>
>> Tcl now allows 0b for binary in [expr] and [format], which is similar
>> to 'b in verilog.  And of cource 0o and 0x have always hbeen around.
>>
>> Would it be good to add 0d for explicit decimal?
>>
>> I had asked on the chat and one upside is to prevent false parsing of
>> leading 0's in [clock formats] as octal, without having to go through
>> a scan.
>>
>> But a more elegant reason is that it makes the radix definition
>> consistent, so (a) all valid input radixes have a consistent
>> unambiguous input literal format and (b) the d in [format %d] finally
>> finds its complement in scan.
>
> A reasonable request, I'm all for it.  It just needs a TIP.  Here's the implementation:
>
> $ fossil diff generic/tclStrToD.c
> Index: generic/tclStrToD.c
> ==================================================================
> --- generic/tclStrToD.c
> +++ generic/tclStrToD.c
> @@ -661,10 +661,15 @@
>            }
>            if (c == 'o' || c == 'O') {
>                explicitOctal = 1;
>                state = ZERO_O;
>                break;
> +           }
> +           if (c == 'd' || c == 'D') {
> +               flags |= TCL_PARSE_INTEGER_ONLY;
> +               state = DECIMAL;
> +               break;
>            }
> #ifdef TCL_NO_DEPRECATED
>            goto decimal;
> #endif
>            /* FALLTHROUGH */

This feature is fully implemented in branch bsg-0d-radix-prefix.

-Brian




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Brian Griffin-4
I've emailed a draft TIP to Donal already, but I know he's busy and the TIP system is in transition, so we may have to wait and see what happens. 

-Brian
(from mobile device)

On May 27, 2017, at 19:31, Venks Izod <[hidden email]> wrote:

Thanks Brian,  I can see you're an expert at this stuff - tests docs and all.

I'm still trying to figure out how to TIP this.   The TIP process says to say email dkf,  
but dkf is obviously busy with bigger sheds than this..

Are there alternatives to a tip?    Show of emails?   We have +2 and -0 so far.  
Unianimous :).

-Venkat


On Sat, May 27, 2017 at 3:45 PM, Brian Griffin <[hidden email]> wrote:

> On May 25, 2017, at 8:08 AM, Brian Griffin <[hidden email]> wrote:
>
>>
>> On May 23, 2017, at 11:28 PM, Venks Izod <[hidden email]> wrote:
>>
>> [First time posting here - please pardon transgressions]
>>
>> I am a hardware (ASIC) designer and often code in Verilog - in
>> addition to Tcl and C and many other languages.
>>
>> Verilog (and other Hardware Description Languages) always (or at least
>> since the 1995 LRM) had a way to specify a decimal number explicitly.
>> Verilog uses 'd343534 to mean decimal, VHDL actually allows any radix
>> from 2 to 16 using syntax, so you could explicitly force a decimal
>> interpretation using 10#343534#.
>>
>> Tcl now allows 0b for binary in [expr] and [format], which is similar
>> to 'b in verilog.  And of cource 0o and 0x have always hbeen around.
>>
>> Would it be good to add 0d for explicit decimal?
>>
>> I had asked on the chat and one upside is to prevent false parsing of
>> leading 0's in [clock formats] as octal, without having to go through
>> a scan.
>>
>> But a more elegant reason is that it makes the radix definition
>> consistent, so (a) all valid input radixes have a consistent
>> unambiguous input literal format and (b) the d in [format %d] finally
>> finds its complement in scan.
>
> A reasonable request, I'm all for it.  It just needs a TIP.  Here's the implementation:
>
> $ fossil diff generic/tclStrToD.c
> Index: generic/tclStrToD.c
> ==================================================================
> --- generic/tclStrToD.c
> +++ generic/tclStrToD.c
> @@ -661,10 +661,15 @@
>            }
>            if (c == 'o' || c == 'O') {
>                explicitOctal = 1;
>                state = ZERO_O;
>                break;
> +           }
> +           if (c == 'd' || c == 'D') {
> +               flags |= TCL_PARSE_INTEGER_ONLY;
> +               state = DECIMAL;
> +               break;
>            }
> #ifdef TCL_NO_DEPRECATED
>            goto decimal;
> #endif
>            /* FALLTHROUGH */

This feature is fully implemented in branch bsg-0d-radix-prefix.

-Brian




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Andreas Leitgeb
Brian Griffin <[hidden email]> wrote:
> This feature is fully implemented in branch bsg-0d-radix-prefix.

I think, the neighbourhood of that change:
  http://core.tcl.tk/tcl/info/a3d2988c14c55537
might wish for 0d-coverage, too.
(LinkVar tries to accept invalid ints that are prefixes of valid ones)

And one thing to clarify:   "0d3.14159"
Can 0d be prefixed only to integral values, or to decimals as well?


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Venks Izod
Well I only thought of 0d to represent integers (like the related 0b, 0o and 0x).
I don't see a strong reason for why they should be limited, but this seems to be true
in all the languages I know.    Floating point numbers (with a decimal point and/or with an
exponent) have to be specified in decimal.

Thanks

-Venkat

On Sun, May 28, 2017 at 1:19 AM, Andreas Leitgeb <[hidden email]> wrote:
Brian Griffin <[hidden email]> wrote:
> This feature is fully implemented in branch bsg-0d-radix-prefix.

I think, the neighbourhood of that change:
  http://core.tcl.tk/tcl/info/a3d2988c14c55537
might wish for 0d-coverage, too.
(LinkVar tries to accept invalid ints that are prefixes of valid ones)

And one thing to clarify:   "0d3.14159"
Can 0d be prefixed only to integral values, or to decimals as well?


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Donald Porter
In reply to this post by Brian Griffin-4

>> Would it be good to add 0d for explicit decimal?

You will want to determine whether and how this will
be treated by the [scan] command, and why whatever
choice you make is correct.

DGP

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Brian Griffin-4
In reply to this post by Andreas Leitgeb

On May 28, 2017, at 1:19 AM, Andreas Leitgeb <[hidden email]> wrote:

Brian Griffin <[hidden email]> wrote:
This feature is fully implemented in branch bsg-0d-radix-prefix.

I think, the neighbourhood of that change:
 http://core.tcl.tk/tcl/info/a3d2988c14c55537
might wish for 0d-coverage, too.
(LinkVar tries to accept invalid ints that are prefixes of valid ones)

Thanks for pointing this out.  I've updated the code accordingly.


And one thing to clarify:   "0d3.14159"
Can 0d be prefixed only to integral values, or to decimals as well?

Yes, 0d is integer only as is 0x, 0b, and 0o.
It's useful as a way to "type cast" a literal value.

-Brian

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decimal prefix for numbers

Brian Griffin-4
In reply to this post by Donald Porter

On May 28, 2017, at 8:26 AM, Donald Porter <[hidden email]> wrote:


>> Would it be good to add 0d for explicit decimal?

You will want to determine whether and how this will
be treated by the [scan] command, and why whatever
choice you make is correct.

It is my intent to match corresponding semantics of 0x in all cases.  I'm not sure what justification there would be for 0d having different semantics from 0x.

-Brian

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Loading...