乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 73|回复: 9

[编程交流] 写入大于32767的整数

[复制链接]

27

主题

72

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
135
发表于 2022-7-5 19:54:36 | 显示全部楼层 |阅读模式
如何使用lisp编写大于32767的文本整数。
当我键入123456时,消息是“需要一个介于-32768和32767之间的整数”
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:06:31 | 显示全部楼层
使用getreal或getstring提示用户输入,测试输入的有效性,并将其转换为整数。
 
32767限制是AutoCAD早期版本中使用16位有符号整数的结果。
回复

使用道具 举报

27

主题

72

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
135
发表于 2022-7-5 20:13:37 | 显示全部楼层
谢谢李。但我不明白这是我的代码怎么办?
  1. (defun C:kk (/ input start rot count ang inc pt1)
  2. (setq count (getint "Enter Starting No.: "))
  3. (if (null count) (setq count 1))
  4. (setq inc 1)
  5. (setq th (getint "\nEnter text height: "))
  6. (if (null th) (setq th 1.27))
  7. ;; set continue flag to True
  8. (setq continue T)
  9. (while continue
  10. (setq input (getpoint (strcat "\nInsertion point for number")))
  11. ;; evaluate user input
  12. (cond
  13. (T
  14. (command "text" "s" "Standard" "mc" input 2 0 count)
  15. (setq pt1 input)
  16. (setq count (+ count inc)))   
  17. )
  18. )
  19. (princ)
  20. )
回复

使用道具 举报

24

主题

1265

帖子

1028

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
362
发表于 2022-7-5 20:16:17 | 显示全部楼层
也许是这样?
 
  1. (initget 5)
  2. (setq lgint (fix (getreal "\nEnter value ")))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:22:47 | 显示全部楼层
RK的解决方案很好-
 
或者,这里还有两个选项可以在提升16位限制的同时模拟标准getint函数的行为:
  1. (defun mygetint ( msg / rtn )
  2.    (while
  3.        (and (setq rtn (getreal msg))
  4.             (not (equal rtn (setq rtn (atoi (rtos rtn 2 0))) 1e-)
  5.        )
  6.        (princ "\nRequires an integer value.")
  7.    )
  8.    rtn
  9. )
  1. (defun mygetint ( msg / rtn )
  2.    (while
  3.        (and (setq rtn (getstring msg))
  4.             (/=  'int (type (setq rtn (read rtn))))
  5.        )
  6.        (princ "\nRequires an integer value.")
  7.    )
  8.    rtn
  9. )
  1. (defun c:test ( )
  2.    (mygetint "\nEnter a number: ")
  3. )
回复

使用道具 举报

27

主题

72

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
135
发表于 2022-7-5 20:28:17 | 显示全部楼层
尊敬的RK&Lee,当我输入123456时,输出为-7616
回复

使用道具 举报

24

主题

1265

帖子

1028

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
362
发表于 2022-7-5 20:39:58 | 显示全部楼层
 
奇怪的它在这里起作用。
 
  1. _$ (initget 5)
  2. nil
  3. _$ (fix (getreal "\nEnter value "))  <---- I entered "123456" at the command prompt.
  4. 123456
回复

使用道具 举报

27

主题

72

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
135
发表于 2022-7-5 20:47:49 | 显示全部楼层
也许 吧:
 
  1. (defun C:kk (/ input start rot count ang inc pt1)
  2. ;(setq count (getint "Enter Starting No.: "))
  3. _$ (initget 5)
  4. nil
  5. _$ (setq count (fix (getreal "\nEnter value ")))
  6. (if (null count) (setq count 1))
  7. (setq inc 1)
  8. (setq th (getint "\nEnter text height: "))
  9. (if (null th) (setq th 1.27))
  10. ;; set continue flag to True
  11. (setq continue T)
  12. (while continue
  13. (setq input (getpoint (strcat "\nInsertion point for number")))
  14. ;; evaluate user input
  15. (cond
  16. (T
  17. (command "text" "s" "Standard" "mc" input 2 0 count)
  18. (setq pt1 input)
  19. (setq count (+ count inc)))   
  20. )
  21. )
  22. (princ)
  23. )
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 20:50:16 | 显示全部楼层
你在运行什么操作系统?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 20:58:44 | 显示全部楼层
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 00:42 , Processed in 0.404030 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表