Re: Issue with small floating point numbers
On Thursday, 13 May 2021 at 03:03:37 UTC, Tim wrote: Hello all, I have this piece of code ```D /** Rotate a 2D array (Vector) by phi radians Params: vec = 2D Vector to rotate phi = Degree with which to rotate the Vector in radians Returns: Rotated 2D array (Vector) Example: */ pragma(inline, true) Point2 rotate2D(in Point2 vec, in float phi) pure nothrow { double x = (vec[0]*cos(phi)) - (vec[1]*sin(phi)); double y = (vec[0]*sin(phi)) + (vec[1]*cos(phi)); return [x, y]; } unittest{ auto p = rotate2D([0.0, 10.0], PI_2); assert(p == [-10.0, 0.0]); } ``` When I run the unittest, I get ```[-10, -4.37114e-07]``` back, which is obviously wrong. Any idea as to why it's not making the y-axis zero? Is it a rounding issue with the types I'm using? Thanks in advance You should try to use isClose to compare for floats equality : https://dlang.org/phobos/std_math.html#.isClose Float arithmetic isn't exact, and could give unexpected results like 0.1f + 0.2f != 0.3f
Re: It's DUB's "optional": true broken ?
On Sunday, 28 March 2021 at 15:52:43 UTC, Zardoz wrote: So, we get this dub.json : { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "library", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "silly": "~>1.0.2", "dshould": "~>1.4.3" } } ] } Where "dshould have a dependency to unit-threaded marked as "optional", and not have any "default" set to true. DUB documentation says that the proyect not must pick the optional dependency if I not edit manualy dub.selections.json to pick unit-threaded. Well.. DUB ignores and picks unit-threaded as I can show here : $ dub build Performing "debug" build using /usr/bin/dmd for x86_64. sybok ~master: building configuration "sybok"... $ dub test Generating test runner configuration 'sybok-test-unittest' for 'unittest' (library). Performing "unittest" build using /usr/bin/dmd for x86_64. prettyprint 1.0.7: building configuration "library"... unit-threaded:from 1.0.14: building configuration "library"... unit-threaded:exception 1.0.14: building configuration "library"... unit-threaded:assertions 1.0.14: building configuration "library"... unit-threaded:integration 1.0.14: building configuration "library"... unit-threaded:mocks 1.0.14: building configuration "library"... unit-threaded:property 1.0.14: building configuration "default"... unit-threaded:runner 1.0.14: building configuration "library"... unit-threaded 1.0.14: building configuration "library"... dshould 1.4.3: building configuration "library"... sybok ~master: building configuration "sybok-test-unittest"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./sybok-test-unittest ✓ sybok_spec Sybock test Summary: 1 passed, 0 failed in 0 ms And dub.selections.json show this : { "fileVersion": 1, "versions": { "dshould": "1.4.3", "prettyprint": "1.0.7", "silly": "1.0.2", "unit-threaded": "1.0.14" } } Plus, If edit dub.selections.json to remove unit-threaded , every time that I launch dub test, overwrites dub.selections.json and picks again unit-threaded. From my point of view, or documentation it's wrong, or there it's something really broken about this functionality. I think that I can self-answer me. Looks that this related to this : https://github.com/dlang/dub/issues/1706 DUB it's downloading unit-threaded, but not linking against it or using it for run the unit tests. It's more evident if I invert the situation : If I have this dub.json { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "executable", - "preBuildCommands": ["$DUB run --compiler=$$DC unit-threaded -c gen_ut_main -- -f bin/ut.d -d $DUB"], - "mainSourceFile": "bin/ut.d", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "unit-threaded": "~>1.0.14", "pijamas": "~develop" } } ] } Uses unit-threaded runner, as is expected. If I use this dub.json : { "name": "example", "configurations": [ { "name": "v", "targetType": "library" }, { "name": "unittest", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "unit-threaded": "~>1.0.14", "pijamas": "~develop" } } ] } Uses the default unit tests runner and not Silly runner that it's leaked from pijamas (Pijamas uses Silly on a "unittest" config, but DUB downloads Silly, even when this project it's using it. This behavior should be on DUB's documentation. It's pretty confusing seeing that DUB it's downloading libraries that would never use, and gives the false impression that it's using it.
Re: How to update terminal output?
On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote: I mean, I want to write a string without a new line. For example, some command line applications have progress bars. For a single line string I use \r. But it doesn't work for a multiple line string - the application is just adding new lines. You must use ANSI control codes to repositionate the cursor or use a library like ncurses that handle this kind of stuff. https://code.dlang.org/search?q=ncurses In particular , nice-curses have a class to generate a TUI progress bar
It's DUB's "optional": true broken ?
So, we get this dub.json : { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "library", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "silly": "~>1.0.2", "dshould": "~>1.4.3" } } ] } Where "dshould have a dependency to unit-threaded marked as "optional", and not have any "default" set to true. DUB documentation says that the proyect not must pick the optional dependency if I not edit manualy dub.selections.json to pick unit-threaded. Well.. DUB ignores and picks unit-threaded as I can show here : $ dub build Performing "debug" build using /usr/bin/dmd for x86_64. sybok ~master: building configuration "sybok"... $ dub test Generating test runner configuration 'sybok-test-unittest' for 'unittest' (library). Performing "unittest" build using /usr/bin/dmd for x86_64. prettyprint 1.0.7: building configuration "library"... unit-threaded:from 1.0.14: building configuration "library"... unit-threaded:exception 1.0.14: building configuration "library"... unit-threaded:assertions 1.0.14: building configuration "library"... unit-threaded:integration 1.0.14: building configuration "library"... unit-threaded:mocks 1.0.14: building configuration "library"... unit-threaded:property 1.0.14: building configuration "default"... unit-threaded:runner 1.0.14: building configuration "library"... unit-threaded 1.0.14: building configuration "library"... dshould 1.4.3: building configuration "library"... sybok ~master: building configuration "sybok-test-unittest"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./sybok-test-unittest ✓ sybok_spec Sybock test Summary: 1 passed, 0 failed in 0 ms And dub.selections.json show this : { "fileVersion": 1, "versions": { "dshould": "1.4.3", "prettyprint": "1.0.7", "silly": "1.0.2", "unit-threaded": "1.0.14" } } Plus, If edit dub.selections.json to remove unit-threaded , every time that I launch dub test, overwrites dub.selections.json and picks again unit-threaded. From my point of view, or documentation it's wrong, or there it's something really broken about this functionality.
Re: Does GtkD work well on Windows?
On Thursday, 24 March 2016 at 21:00:36 UTC, Web Biz Owner wrote: Hi group, I'm interested in developing some GUI programs in D on Windows. Looked into the various D GUI toolkit options a bit, on the D sites and by googling a bit. Thinking of using GtkD. So would like to know whether people think it is a good option for GUI app dev on Windows. Note: I have not ruled out other toolkits. If anyone has any thoughts on their use, please do comment. Thanks, W.B.O. Short answer : Yes, but you need to install (or package with) Gtk dlls. Long answer : Install following this instructions : https://github.com/gtkd-developers/GtkD/wiki/Installing-on-Windows If you would use Dub and you need to be cross-platform, the dub.sdl/json would be a bit more tricky, but works. You would need something like this : libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" targetType "executable" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" targetType "executable" }
Re: Using tango or other static lib in static lib
On Sunday, 13 March 2016 at 01:08:29 UTC, Mike Parker wrote: On Sunday, 13 March 2016 at 01:06:33 UTC, Mike Parker wrote: it. Assuming both files live in the same directory, they can be compiled with this command: Somehow I deleted that line: dmd main.d something.d Not would be more easy to simply add a dependency to tango on dub.SDL ? I ask...
Re: How to better organize dub project to get 3 exe from same codebase?
On Saturday, 27 February 2016 at 13:56:21 UTC, Suliman wrote: What I am doing wrong? http://img.ctrlv.in/img/16/02/27/56d1aae37b77a.png Try : dub build code1:App1 dub build code1:App2
Re: How to better organize dub project to get 3 exe from same codebase?
On Thursday, 25 February 2016 at 18:57:08 UTC, Suliman wrote: I have got 3 small projects that have shared code base. At compile time they use few same classes. On runtime they use same config file. How to better to organize work with dub? Try with subpacjages like I did : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" targetType "executable" targetName "lem1802" libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } } subPackage { name "bconv" description "Binary file conversor. Converts between different data files for DCPU-16 emulators" targetType "executable" targetName "bconv" excludedSourceFiles "src/lem1802_fontview.d" excludedSourceFiles "src/ddis.d" excludedSourceFiles "src/ui/*" } subPackage { name "ddis" description "Dis-assembler for DCPU-16. Generates a DCPU-16 assembly dump from a binary file." targetType "executable" targetName "ddis" excludedSourceFiles "src/lem1802_fontview.d" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ui/*" } https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl
Re: Running task once a day in vibe.d
On Tuesday, 16 February 2016 at 18:30:43 UTC, Nick wrote: Hey folks I'm making a vibe.d application. Once a day it needs to download some data. How do i get the program to perform this task once a day? Regards, Nick Why you not use cron to launch your program at desire time every day ?
Re: How to Generate Entities from an Existing Database in D language ORM?
On Monday, 15 February 2016 at 14:33:24 UTC, Eliatto wrote: Hello! I've found the following C++/Qt project: http://www.treefrogframework.org/ It contains ORM. Treefrog can generate model stubs from the existing database. Is it possible to do the same in any D language ORM library? BTW, similar situation was discussed here: http://programmers.stackexchange.com/questions/299715/using-orms-in-two-separate-programs-which-share-a-db Perhaps you can use liquidbase to generate an XML or json representation and use it to generate hibernated entities. I don't know yet enough about ddbc to say anything Bout his capacity to read the database structure. jDBC can do this, so I expect that DDBC have the same capacity.
Re: DUB, Platform specifications and dependencies
On Monday, 30 November 2015 at 16:54:43 UTC, Sönke Ludwig wrote: Am 24.11.2015 um 19:51 schrieb Zardoz: Actually I'm trying to setup dub to not grab a dependency on Windows ( https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl ) : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" dependency "gtk-d:gtkd" version="~>3.2.0" platform="posix" libs "gtkd" platform="windows" } ... How ever, running dub on Windows (tested on two different machines), ignores platform specification for gtk-d dependency . What I'm doing wrong ? Platform specifications are currently not supported for dependencies due to the way the dependency resolver works. However, it is possible to use platform specific configurations for this purpose: name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } } Thanks!! I ended doing some minor change to get it working : subPackage { name "lem1802" description "Visual LEM1802 font editor" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" configuration "nogtk" { targetType "executable" targetName "lem1802" platform "windows" libs "gtkd" } configuration "gtk" { targetType "executable" targetName "lem1802" platform "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } }
DUB, Platform specifications and dependencies
Actually I'm trying to setup dub to not grab a dependency on Windows ( https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl ) : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" dependency "gtk-d:gtkd" version="~>3.2.0" platform="posix" libs "gtkd" platform="windows" } ... How ever, running dub on Windows (tested on two different machines), ignores platform specification for gtk-d dependency . What I'm doing wrong ?