Home Register Calendar Today's Posts FAQ Search
 DirectX Topics include: Managed DirectX (DX9)

Enjoy an ad free experience by logging in. Not a member yet? Register.
 > .NET > Debug error "Cannot convert from double to float...

#1
04-02-2012, 09:53 AM
 SleepingTroll Newcomer Join Date: Feb 2012 Posts: 12
Debug error "Cannot convert from double to float...

 Velocity[a] is a Vector3 type (all doubles), Proximity is a double as is Influence. The highlighted code produces a cannot convert double to float error... I have tried (double)0 and that did not solve the problem. Any ideas? Code: ```Velocity[a] = (new Vector3( Proximity.X != 0 ? Velocity[a].X + (1/(Influence * Proximity.X)) : Velocity[a].X, Proximity.Y != 0 ? Velocity[a].Y + (1/(Influence * Proximity.Y)) : Velocity[a].Y, Proximity.Z != 0 ? Velocity[a].Z + (1/(Influence * Proximity.Z)) : Velocity[a].Z ));```

Last edited by snarfblam; 04-02-2012 at 05:52 PM. Reason: [Code] tags and formatting help *a lot*
#2
04-02-2012, 06:01 PM
 snarfblam Ultimate ContributorPreferred language:C#, VB Join Date: Jun 2003 Location: USA Posts: 2,097
Re: Debug error "Cannot convert from double to float...

 You're code is a bit hard to read. While that might sound nit-picky, and it's a subjective thing, when code is more readable, it is easier to understand and reason about it, especially at a glance. It also helps us help you. The documentation for Vector3 states that the fields are floats, not doubles. You either need to cast to float, or make sure that all of your variables are floats rather than doubles. Something like this should work. Code: ```Velocity[a] = (new Vector3( Proximity.X != 0 ? (float)(Velocity[a].X + (1/(Influence * Proximity.X))) : Velocity[a].X, Proximity.Y != 0 ? (float)(Velocity[a].Y + (1/(Influence * Proximity.Y))) : Velocity[a].Y, Proximity.Z != 0 ? (float)(Velocity[a].Z + (1/(Influence * Proximity.Z))) : Velocity[a].Z ));```
__________________
#3
04-03-2012, 10:16 AM
 SleepingTroll Newcomer Join Date: Feb 2012 Posts: 12
Re: Debug error "Cannot convert from double to float...

 I had assumed that a Vector3 type used double values... bad assumption!

 Bookmarks

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Announcements .NET     General     Windows Forms     ASP.NET     Directory / File IO / Registry     Database / XML / Reporting     Network     Graphics and Multimedia         DirectX     Interoperation / Office Integration     Deployment     Regular Expressions     Syntax Specific         Visual Basic .NET         Visual C# .NET         Visual J# .NET         Visual C++ .NET         JScript .NET Knowledge Base     Tutors Corner     Code Library General Discussion     Random Thoughts     Suggestions, Bugs, and Comments

 Similar Threads Thread Thread Starter Forum Replies Last Post Jelmer General 2 03-02-2006 09:29 AM karlhaak ASP.NET 1 08-10-2004 02:27 PM cathiec General 4 03-11-2004 10:21 AM cmaras Database / XML / Reporting 7 11-03-2003 11:23 AM bobmack37 General 2 04-22-2003 10:52 PM

 Free Publications The ASP.NET 2.0 Anthology 101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe Programmers Heaven C# School Book -Free 338 Page eBook The Programmers Heaven C# School book covers the .NET framework and the C# language. subscribe Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview! This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time.. subscribe
 Home Register Calendar Today's Posts FAQ Archive