Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. TypeCasting

TypeCasting

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KKR
    wrote on last edited by
    #1

    I need to fill the array asfollows const float feature_scal_intervall_low[NR_FEATURES] = { 0.1,0.0,0.1,0.1,0.3 ,0.2,0.1,0.1,0.0,0.2 }; Getting Warning : warning C4305: 'initializing' : truncation from 'const double' to 'const float' How to typecast above array?? Any Suggesstions. Thanks in advance Warm Regards, KKRam

    R J 2 Replies Last reply
    0
    • K KKR

      I need to fill the array asfollows const float feature_scal_intervall_low[NR_FEATURES] = { 0.1,0.0,0.1,0.1,0.3 ,0.2,0.1,0.1,0.0,0.2 }; Getting Warning : warning C4305: 'initializing' : truncation from 'const double' to 'const float' How to typecast above array?? Any Suggesstions. Thanks in advance Warm Regards, KKRam

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      Numbers written in 0.1 format are treated as doubles, to get he compiler to treat them as floats write them as 0.1f Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

      1 Reply Last reply
      0
      • K KKR

        I need to fill the array asfollows const float feature_scal_intervall_low[NR_FEATURES] = { 0.1,0.0,0.1,0.1,0.3 ,0.2,0.1,0.1,0.0,0.2 }; Getting Warning : warning C4305: 'initializing' : truncation from 'const double' to 'const float' How to typecast above array?? Any Suggesstions. Thanks in advance Warm Regards, KKRam

        J Offline
        J Offline
        Jagadeesh VN
        wrote on last edited by
        #3

        Its always better to use a 'double' array instead of float. If you are very specific about float array, you can initialize it by explicitly type-casting each element as shown below. const float feature_scal_intervall_low[ NR_FEATURES ] = { (float)0.1,(float)0.0,(float)0.1,(float)0.1,(float)0.3 ,(float)0.2,(float)0.1,(float)0.1,(float)0.0,(float)0.2 }; "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups