Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NARS1] [ksbhaskar] %HD should also work on hexadecimal numbers with a 0x or 0X prefix #45

Merged
merged 4 commits into from
Oct 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sr_port/hd.mpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Copyright 1987,2001 Sanchez Computer Associates, Inc. ;
; Copyright 1987,2001 Sanchez Computer Associates, Inc. ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a matter of esthetics, but the semi-colon box doesn't line up, at least on the Github review.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is likely because I have replaced the end of the line with tabs (instead of spaces) and that is how all lines in the rest of the copyright notice are. I do see all lines aligned in the actual code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

; ;
; Copyright (c) 2017 YottaDB LLC. and/or its subsidiaries. ;
; All rights reserved. ;
; ;
; This source code contains the intellectual property ;
; of its copyright holder(s), and is made available ;
Expand All @@ -11,13 +14,17 @@
%HD ;GT.M %HD utility - hexadecimal to decimal conversion program
;invoke at INT with %HD in hexadecimal to return %HD in decimal
;invoke at FUNC as an extrinsic function
;Note: works even if input hex number contains 0x or 0X prefix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Ignores any prefix of 0x or 0X

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in next commit. Please review that.

;if you make heavy use of this routine, consider $ZCALL
;
s %HD=$$FUNC(%HD)
q
INT r !,"Hexidecimal: ",%HD s %HD=$$FUNC(%HD)
q
FUNC(h)
n prefix
set prefix=$zextract(h,1,2)
set:(("0X"=prefix)!("0x"=prefix)) h=($zextract(h,3,99))
q:$tr(h,"E","e")<0 ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is not part of this change, but this seems like a strange and inefficient way to test whether the input is a decimal number less than zero. Why not just something like q:+h<0 ""? Or do I not understand what this line is doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is most likely to avoid NUMOFLOW errors. See example below E vs e.

YDB>s h="1E98" 
YDB>w h<0
%GTM-E-NUMOFLOW, Numeric overflow

YDB>s h="1e98"
YDB>w h<0
0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

n c,d,dg
s d=0,h=$tr(h,"abcdef","ABCDEF")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of inserting lines 25 through 27, why not change line 30 to: s d=0,h=$tr(h,"abcdefx","ABCDEFX") s:"0X"=$e(h,1,2) $e(h,3,$l(h))?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will do.

Expand Down