Evaluating a floating point variable in Scheme language

落爺英雄遲暮 提交于 2019-12-02 08:14:15

问题


I want to read multiple data files (10 in total) in Ansys Fluent. I wrote a journal file which uses scheme language

(Do ((count 11.100 (+ count 0.100))) ((>= count 12.000))
(ti-menu-load-string (format #f "file read-data data-~a.dat" count)))

The format of the file name is like data-11.200.dat, but the program reads it as data-11.2.dat. How I can force it to read the floating point numbers after the decimal point?

Of course I can rename the data files, but that is not useful for I have to use the code many times. I have tried data-~03d.dat, but that didn't work!


回答1:


Try this:

(do ((count 111/10 (+ count 1/10))) ((>= count 12))
  (ti-menu-load-string 
   (format #f "file read-data data-~2,3F.dat" count)))

I assume format is from SRFI-48 Intermediate Format Strings. I've changed the numbers to rational numbers because adding 0.1 gives you rounding errors in floating point.




回答2:


I think I have figured that out:

data-~.3f.dat


来源:https://stackoverflow.com/questions/47822902/evaluating-a-floating-point-variable-in-scheme-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!